使用Hapi.js运行第三方命令行工具

在我的应用程序中,我需要使用一个命令行工具,但是我没有看到任何方式去做,而不使用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) { });