matori82
matori82

Reputation: 3839

How to output timestamp when node.js server is restarted via grunt-nodemon?

I have simple hello world nodejs express application and I just added grunt-nodemon that should watch changes on *.js files. Here is the console output I get when I run grunt and then change some .js file:

Running "nodemon:dev" (nodemon) task             
[nodemon] v1.3.7                                 
[nodemon] to restart at any time, enter `rs`     
[nodemon] watching: *.*                          
[nodemon] starting `node server.js`              
Example app listening at http://:::3000          
[nodemon] restarting due to changes...           
[nodemon] starting `node server.js`              
Example app listening at http://:::3000     

Is there a way to see timestamp prepended to each of these lines in console log? Eg.

18:44:21 - Running "nodemon:dev" (nodemon) task             
18:44:21 - [nodemon] v1.3.7                                 
18:44:21 - [nodemon] to restart at any time, enter `rs`     
...

I'd like to see in console when was the last server restart. Here is my gruntfile.js:

module.exports = function (grunt) {
  grunt.initConfig({
    nodemon: {
      dev: {
        script: 'server.js',
        options: {
          ext: ['js']
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-nodemon');
  grunt.registerTask('default', ['nodemon'])
};

Upvotes: 1

Views: 798

Answers (1)

knolleary
knolleary

Reputation: 10117

Rather than try to modify the output of nodemon, a cleaner approach would be for your application to log the timestamp when it starts up.

If you use the util.log function rather than console.log, you'll get the timestamp added automatically to your log messages.

Upvotes: 3

Related Questions