Chin
Chin

Reputation: 12712

node - restart server after editing specific files

I'd like to automatically restart the server after particular files are edited. Is there anything I can install to help me do that? - or will I need to watch the folder run a script accordingly. Any pointers appreciated

Upvotes: 4

Views: 1031

Answers (4)

learner_19
learner_19

Reputation: 4101

Nodemon is good for it https://github.com/remy/nodemon Also, if you want nodemon to restart your app only if particular files are changed, it is important to have .nodemonignore file in which you can tell changes to which files should be ignored by nodemon.

Example .nodemonignore file :

/public/*   # ignore all public resources

/.*         # any hidden (dot) files

*.md        # Markdown files

*.css       # CSS files

.build/*    # Build folder

/log/*

Upvotes: 0

Daniel Steigerwald
Daniel Steigerwald

Reputation: 1101

https://github.com/mdlawson/piping is good too.

There are already node "wrappers" that handle watching for file changes and restarting your application (such as node-supervisor), as well as reloading on crash, but I wasn't fond of having that. Piping adds "hot reloading" functionality to node, watching all your project files and reloading when anything changes, without requiring a "wrapper" binary.

Upvotes: 0

alessioalex
alessioalex

Reputation: 63673

You could use Nodemon for that, there is even a video tutorial on it.

Upvotes: 0

zatatatata
zatatatata

Reputation: 4821

Use supervisor. Install it with npm install supervisor -g and launch your code with supervisor server.js and you should be good to go. Note that by default it keeps an eye on the files that are in the same directory as the server.js and it's subdirectories, but it should be possible to add additional paths.

Upvotes: 7

Related Questions