gulp.task('server', function (cb) { exec('node lib/app.js', function (err, stdout, stderr) { console.log(stdout); console.log(stderr); cb(err); }); exec('mongod --dbpath ./data', function (err, stdout, stderr) { console.log(stdout); console.log(stderr); cb(err); });})供以后参考,以及是否有人遇到此问题。
上面的代码解决了我的问题。因此,基本上,我发现上述内容是它自己的功能,因此不需要:
.pipe
我以为这段代码:
exec('start server', function (err, stdout, stderr) {是我正在运行的任务的名称,但这实际上是我将要运行的命令。因此,我将其更改为指向运行我的服务器的app.js,并做了同样的操作以指向我的MongoDB。
编辑
正如下面提到的@ N1mr0d,没有服务器输出,一种更好的运行服务器的方法是使用nodemon。您可以
nodemonserver.js像奔跑一样简单地奔跑
node server.js。
下面的代码段是我在gulp任务中使用nodemon现在运行服务器的内容:
// start our server and listen for changesgulp.task('server', function() { // configure nodemon nodemon({ // the script to run the app script: 'server.js', // this listens to changes in any of these files/routes and restarts the application watch: ["server.js", "app.js", "routes/", 'public**'], ext: 'js' // Below i'm using es6 arrow functions but you can remove the arrow and have it a normal .on('restart', function() { // then place your stuff in here } }).on('restart', () => { gulp.src('server.js') // I've added notify, which displays a message on restart. Was more for me to test so you can remove this .pipe(notify('Running the start tasks and stuff')); });});链接安装Nodemon:https
://www.npmjs.com/package/gulp-nodemon



