如何在 Node.js 中使用 k6

How to use k6 in Node JS

我需要从节点 js 脚本使用 k6 发送请求

我已经试过了:

import http from "k6/http"; 

还有这个:

var http = require('k6/http')

但没有成功

UPD

我想像这样使用 k6: 节点 js 脚本:

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

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

您不能在 node.js 或 k6 以外的任何其他地方使用 k6/http 或任何其他 k6/* 模块。那些模块是不是写在JavaScript,它们是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,而不是node.js。