在我的应用程序中,我需要使用命令行工具,但我还没有看到任何不使用npm模块的方法。除了命令行工具外,我正在使用核心节点。
您可以使用节点的child_process
模块。以下是在处理程序中调用touch
命令的示例:
var ChildProcess = require('child_process');
var Hapi = require('hapi');
var server = new Hapi.Server();
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
ChildProcess.exec('touch example.txt', function (err) {
console.log('FILE CREATED');
});
process.on('exit', function (code) {
console.log('PROCESS FINISHED');
reply();
});
}
});
server.inject('/', function (res) { });