Search code examples
javascriptnode.jsexpressgulp

Starting an express server from within gulp


I have a server.js file in the same directory with gulpfile.js. In gulpfile.js I require my server.js file:

var express = require('./server.js')

I want to run it in the default task:

gulp.task('default' , [ 'build','watch','connect'] , function(){
    gulp.run('express');
});

I tried to run it like that but it didn't work. I suppose you can run only tasks in that way. How can I run it in default task?

The server.js file includes this code:

var express = require('express');
var app = express(); 

app.get('/api/test', function(req,res){
  res.send('Hello world!')
});

app.listen(3000, function(){
  console.log('Example app listening on port 3000!');
})

Solution

  • The solution to that would be just replacing my code with the following :

    gulp.task('default' , [ 'build','watch','connect'] , function(){
      express;
    });