How to properly return a response from Gulp tasks

Starting with version 4, Gulp has become more strict about tasks return type. You have five ways to return a proper gulp response from tasks:

Return a Stream

const print = require('gulp-print');

gulp.task('message', function() {
  return gulp.src('package.json')
    .pipe(print(function() { 
        return 'HTTP Server Started';
    }));
});

Return a Promise

gulp.task('message', function() { 
  return new Promise(function(resolve, reject) {
    console.log("HTTP Server Started");
    resolve();
  });
});

Call the callback function

gulp.task('message', function(done) {
  console.log("HTTP Server Started");
  done();
});

Return a child process

This is not very portable:

var spawn = require('child_process').spawn;

gulp.task('message', function() {
  return spawn('echo', ['HTTP', 'Server', 'Started'], { stdio: 'inherit' });
});

Return a RxJS Observable.

var Observable = require('rx').Observable;

gulp.task('message', function() {
  var o = Observable.just('HTTP Server Started');
  o.subscribe(function(str) {
    console.log(str);
  });
  return o;
});