Node.js 如何在expressjs上将API(路由)转换为CLI
例如: 我有一条这样的路线:Node.js 如何在expressjs上将API(路由)转换为CLI,node.js,api,express,routes,command-line-interface,Node.js,Api,Express,Routes,Command Line Interface,例如: 我有一条这样的路线: http://localhost:3000/source1/test 现在我想通过以下方式运行它: node index.js --first=source1 --second=test 我该怎么做?我们可以使用模块: 然后我们可以使用开关盒来完成我们想要的功能。然而,我们必须将所有API转换为带参数的普通函数 const commandLineArgs = require('command-line-args'); const optionDefinitio
http://localhost:3000/source1/test
现在我想通过以下方式运行它:
node index.js --first=source1 --second=test
我该怎么做?我们可以使用模块: 然后我们可以使用开关盒来完成我们想要的功能。然而,我们必须将所有API转换为带参数的普通函数
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{name: 'route', alias: 'r', type: String}
];
const option = commandLineArgs(optionDefinitions);