1

在我的应用程序中,我需要使用命令行工具,但我还没有看到不使用 npm 模块的任何方法。我正在使用除命令行工具外的核心节点。

4

1 回答 1

1

您可以使用节点的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) { });
于 2014-11-09T19:11:37.677 回答