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);
});
})
Na wypadek, gdyby ktoś inny napotkał ten problem.
Powyższy kod naprawił mój problem. Więc w zasadzie, okazało się, że powyższe jest swoją funkcję, a zatem nie trzeba:
.pipe
Myślałem, że ten kod:
exec('start server', function (err, stdout, stderr) {
była nazwa zadania jestem działa jednak to, jakie polecenie będę uruchamiał. Dlatego zmieniłem to tak, aby wskazywało app.js, który uruchamia mój serwer i zrobił to samo, aby wskazać moje MongoDB.
EDIT
Jako @ N1mr0d wymienione poniżej z konieczności nie ma wyjścia Serwer lepszego sposobu, aby uruchomić serwer byłoby użyć nodemon. Możesz po prostu uruchomić nodemon server.js
tak, jakbyś mógł uruchomić node server.js
.
Kod poniżej fragment jest co używam w moim zadaniu haustem uruchomić mój serwer teraz używając nodemon:
// start our server and listen for changes
gulp.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/*', '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'));
});
});
Link do zainstalowania Nodemon: https://www.npmjs.com/package/gulp-nodemon
nb: Nie potrzebujesz modułu gulp-exec. Podany w pierwszym komentarzu "uwaga:" na stronie modułu ➝ https://www.npmjs.com/package/gulp-exec –