3

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.

3 Answers 3

7

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);
  });
})
Sign up to request clarification or add additional context in comments.

3 Comments

what is exec in exec('node bin/www.js',?
you can run os commands with exec, as like as "mkdir app" or "cd folder" or another somethings.
exec = require('child_process').exec
3

There are several plugins available with gulp.

  1. Nodemon (https://www.npmjs.com/package/gulp-nodemon)
  2. Express (https://www.npmjs.com/package/gulp-express)
  3. Develop Server (https://www.npmjs.com/package/gulp-develop-server)

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);
    });
});

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.