3

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/");
John Doe
  • 65
  • 2
  • 6

1 Answers1

12

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.

na--
  • 1,016
  • 7
  • 9
  • got it, so can I use some k6 template script( for ex. send post request), start process from node js and pass custom params to k6 template script? in other words, I mean some like this: `import http from "k6/http"; var spawn = require('child_process').spawn; spawn('k6', ['run','script.js'], { detached: false });` – John Doe Feb 21 '19 at 18:53
  • You can launch a k6 process from inside of a node.js script, yes. But that `import http from "k6/http";` in your example is still impossible. And you cannot use node.js system modules inside of k6 for the same reason you cannot use `k6/*` modules in node.js scripts. – na-- Feb 22 '19 at 07:48