I'd like to manage two apps with one gulpfile. I can launch them both with the following code. However, when I modify one of the files, and gulp.watch restarts the server, I get Error: listen EADDRINUSE. Something must be wrong in my gulp server task, but what is it?
// Dependencies
var gulp = require('gulp'),
spawn = require('child_process').spawn,
node;
// Server Task
gulp.task('server', function() {
if (api) node.kill();
if (dashboard) node.kill();
var api = spawn('node', ['./api/server.js'], {
stdio: 'inherit'
});
var dashboard = spawn('node', ['./dashboard/server.js'], {
stdio: 'inherit'
});
api.on('close', function(code) {
if (code === 8) console.log('API – Error detected, waiting for changes...');
});
dashboard.on('close', function(code) {
if (code === 8) console.log('Dashboard – Error detected, waiting for changes...');
});
});
// Watch Statement
gulp.task('default', ['server'], function() {
// Watch files for changes
gulp.watch(alljsLocations, ['server'], function() {});
});