Nodemon and Grunt-Contrib-Watch: What is the difference ?, No difference

Source: Internet
Author: User

Nodemon and Grunt-Contrib-Watch: What is the difference ?, No difference

I have been usingNodemonAndgrunt-contrib-watch. These are good tools and I think anyone using NodeJS should at least have these in your "I am familiar" category ("I'm familiar "). But since I have been using these tools recently, I have been asking myself, "Why are I using these two tools? Why not stick to one of them? "... Sitting here with me, thinking about my current project, wondering if I can switch everything to one of them and findNodemonAndgrunt-contrib-watch.

Nodemon

The core of Nodemon is a command line tool, which replaces the standardnodeCommand Line to restart the node application as long as a file changes. In most casesnodeReplacenodemon.

Nodemon starts a normal node process and monitors changes in the file system. When nodemon detects that the file has changed, nodemon stops and restarts the node process. This is especially useful for building a node app that has been running for a long time. Like the ExpressJS web application, you can replace the operation that requires manual stopping and restarting the server. You can ask nodemon to help you.

Nodemon makes life simple. When files change, your node process will be restarted.

Grunt-Contrib-Watch

This is also a tool for monitoring changes in the file system. But it does not restart the program when the file system changes. It allows you to do many other things, including running variousGrunt Tasks

In this configuration, I monitor the changes to JavaScript files in the public/javascripts folder and then run the jshint browserify task. There are other things that can be done with grunt-contrib-watch, but its core is also its best, that is, it can execute Grunt Tasks when it detects file changes.

So, What's The Difference?

The real difference --NodemonIs designed to restart node process, andgrunt-contrib-watchIs to run a specific set of grunt tasks. Yes, they both monitor changes in the file system and make some responses, but what they do as a response is the real difference between the two. My applications use bothnodemonAndgrunt-contrib-watchBecause they provide two different purposes. When I change the ExpressJS app. js file or one of my route handlers,nodemonWill intervene and restart the application for me. When I modify the JavaScript file in the public/javascripts folder of the same ExpressJS application,grunt-contrib-watchStep in and run all my tasks under the relevant code. My pairgrunt-contrib-watchDoing more is not just about this, but I think it is a good illustration of their differences.

Shoshould I Use Both?

Finally, I realized that these tools are very complementary. They work together to create an epic NodeJS application development environment. Therefore, they are used at the same time because they have different purposes.

Finally, a gruntfile. js configuration file code is provided.

Module. exports = function (grunt) {grunt. initConfig ({watch: {jade: {files: ['Views/** '], option: {livereload: true}, js: {files: ['Public/js/** ', 'models /**/*. js', 'schemas /**/*. js'], // tasks: ['jshint'], options: {livereload: true }}, nodemon: {dev: {options: {file: 'app. js', args: [], ignoredFiles: ['readme. md ', 'node _ Les /**','. ds_stor'], watchedExtensions: ['js'], watchedFolders: ['app', 'config'], debug: true, delayTime: 1, env: {PORT: 3000 }, cwd :__ dirname }}, concurrent: {tasks: ['nodemon', 'Watch '], options: {logConcurrentOutput: true }}) grunt. loadNpmTasks ('grunt-contrib-Watch'); grunt. loadNpmTasks ('grunt-nodemon'); // After the file is changed, the grunt service is automatically started. loadNpmTasks ('grunt-concurrent'); // Run grunt tasks concurrently concurrent execution task grunt. option ('force', true); // prevents the service from being interrupted due to errors during compilation. registerTask ('default', ['concurrent']); // register the default task}

The level is limited:
Nodemon vs Grunt-Contrib-Watch: What's The Difference?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.