How to console log to stdout on gulp events

0 votes

I want to log to stdout (the config environment) when a gulp task is running or has run.

Something like this:

gulp.task('scripts', function () {
  var enviroment = argv.env || 'development';
  var config = gulp.src('config/' + enviroment + '.json')
      .pipe(ngConstant({name: 'app.config'}));
  var scripts = gulp.src('js/*');

  return es.merge(config, scripts)
    .pipe(concat('app.js'))
    .pipe(gulp.dest('app/dist'))
    .on('success', function() { 
      console.log('Configured environment: ' + environment);
    });
});

I am not sure what event I should be responding to or where to find a list of these. Any pointers?

Oct 12, 2020 in Node-js by kartik
• 37,520 points
6,503 views

1 answer to this question.

0 votes

Hello @kartik,

Use this:

var gulp = require("gulp");
var util = require("gulp-util");
var changed = require("gulp-changed");

gulp.task("copyIfChanged", function() {
    var nSrc=0, nDes=0, dest="build/js";
    gulp.src("app/**/*.js")
    .on("data", function() { nSrc+=1;})
    .pipe(changed(dest)) //filter out src files not newer than dest
    .pipe(gulp.dest(dest))
    .on("data", function() { nDes+=1;})
    .on("finish", function() {
        util.log("Results for app/**/*.js");
        util.log("# src files: ", nSrc);
        util.log("# dest files:", nDes);
    });
}

Hope it helps!!

Thank you!!

answered Oct 12, 2020 by Niroj
• 82,840 points

Related Questions In Node-js

0 votes
1 answer

How to get the available tasks list in gulp?

Hello @kartik,  I got it use the gulp --tasks in ...READ MORE

answered Oct 13, 2020 in Node-js by Niroj
• 82,840 points
1,139 views
0 votes
1 answer

How to save a stream into multiple destinations with Gulp.js?

Hello @kartik, Currently you have to use two ...READ MORE

answered Oct 14, 2020 in Node-js by Niroj
• 82,840 points
1,468 views
0 votes
1 answer

How to run node.js app forever when console is closed?

Hello @kartik, You may also want to consider ...READ MORE

answered Oct 14, 2020 in Node-js by Niroj
• 82,840 points
2,416 views
0 votes
1 answer

How to get Node.JS Express to listen only on localhost?

Hello @kartik, This is a bug in hive-go that only ...READ MORE

answered Oct 16, 2020 in Node-js by Niroj
• 82,840 points
7,407 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
4,230 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,840 points
3,278 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
1,149 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
1,048 views
0 votes
1 answer

How to get GET (query string) variables in Express.js on Node.js?

Hello @kartik, Since you've mentioned Express.js in your ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
3,270 views
0 votes
1 answer

How to run Gulp tasks sequentially one after the other?

Hello @kartik, By default, gulp runs tasks simultaneously, ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,840 points
1,516 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP