I am new to gulp.
I need to run node server using gulp but without using any of its plugin.
Is it possible?
If not then what is the best plugin for it in gulp system.
You should try gulp-nodemon plugin. It's useful plugin for development with node.
// Gulpfile.js
var gulp = require('gulp')
, nodemon = require('gulp-nodemon')
, jshint = require('gulp-jshint')
gulp.task('lint', function () {
gulp.src('./**/*.js')
.pipe(jshint())
})
gulp.task('develop', function () {
nodemon({ script: 'server.js'
, ext: 'html js'
, ignore: ['ignored.js']
, tasks: ['lint'] })
.on('restart', function () {
console.log('restarted!')
})
})
For more details you can visit here.
Also
If you don't want use any plugin, you can start node without it like below:
var gulp = require('gulp')
, exec = require('child_process').exec
gulp.task('nodestart', function (cb) {
exec('node bin/www.js', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
There are several plugins available with gulp.
if you wish to start the node server without any plugin you can try out the following.
var exec = require('child_process').exec;
gulp.task('start', function (callback) {
exec('node server/app.js', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
});
if you are in development environment gulp-supervisor
// Gulpfile.js
var gulp = require( "gulp" ),
supervisor = require( "gulp-supervisor" );
gulp.task( "supervisor-simple", function() {
supervisor( "test/fixture/server.js" );
} );
gulp.task( "supervisor-all", function() {
supervisor( "test/fixture/server.js", {
args: [],
watch: [ "test" ],
ignore: [ "tasks" ],
pollInterval: 500,
extensions: [ "js" ],
exec: "node",
debug: true,
debugBrk: false,
harmony: true,
noRestartOn: false,
forceWatch: true,
quiet: false
} );
} );
if you are in production environment, i recommand gulp pm2 plugin, gulp-connect-pm2