Search code examples
node.jsk6

How to use k6 in Node JS


I need to send requests using k6 from node js script

I have already tried this:

import http from "k6/http"; 

and this:

var http = require('k6/http')

but it didn't work out

UPD

I want to use k6 some like this: node js script:

var http = require('k6/http');
var fs = require('fs');

http.get("http://test.loadimpact.com/");

Solution

  • You cannot use k6/http or any other k6/* modules in node.js, or anywhere else besides k6. Those modules are not written in JavaScript, they are written in Go and are internal for k6 - part of (i.e. compiled in) the k6 binary. They are only accessible from scripts that are ran via k6's JavaScript runtime, which is goja, not node.js.