Nodemon + Express 4.13.4 - node.js

I am losing my mind trying to get Nodemon running correctly with Express 4 ;) I have installed the npm and changed my package.json to
"scripts": {
"start": "nodemon ./bin/www"
},
I launch the server using...
npm start
If I then make any edits to a routes.js file no changes take. Even when I refresh the browser. After running ps aux | grep node I get the following..
It seems that BOTH the Nodemon AND node server are running. Has anyone else seen this and understand why? or how to fix it?
Thanks.
*UPDATE This is my console output while the server is running.

Nodemon only watches the files in the current working directory (in your case ./bin because you're running ./bin/www). Your app files aren't in that directory, so nodemon isn't watching them.
You can, however, tell nodemon to instead watch one or more other directories. In your case you just need to tell it to watch the project root, i.e. nodemon ./bin/www --watch ..
Your jade files are loaded anew on every request by express's view engine, which is why you were seeing changes made in them without you or nodemon restarting the app.
I've made a pull request on your repo which makes npm start use nodemon in this fashion.

Related

Nodemon: is it possible to restart the Node js server on chages ONLY in backend files and NOT in static frontend files?

Recently, I've started using Nodemon to auto-refresh my Node js server on changes in files (it's soooo convenient: previously, I used to stop it manually with sigint and restart the project in the command line again). What I did is installed Nodemon on my PC globally (npm install nodemon -g), and now I start my project with the command nodemon app.js (instead of usual node app.js), and everything seems to be great ... except for one thing that pretty annoys me: the server keeps restarting also on changes in my frontend files which are made static in Express by the command app.use(express.static('frontend')) – which is purposeless, because I don't need to restart the Node js server to apply changes in such files (simply to reload a page in a browser is enough). So, is there a way to "learn" nodemon to ignore static frontend files and not to restart the server on changes in them?
The issue has been solved by installing nodemon locally + adding to package.json the following code (as offered here):
"scripts": {
"start": "nodemon app.js"
},
"nodemonConfig": {
"ignore": [
"frontend/*"
]
}
Now, if I launch the project either with nodemon app.js, or with npm start, changes in all the files within the frontend folder are ignored.

NodeJS close server and start again

I am brand new to React and NodeJS. I have NodeJS latest version installed on my mac as well as React. I can start and run the app using npm start I am following tutorials and it was fine and I could see my app in the browser. The problem begins when I need to finish for the day and start again the next day and I do not know how to start the server again and app and to continue the work. npm start does not work. Unfortunately tutorials only show how to start the app for the very first time, but they don't show what do you need to do to interrupt your work, shut down computer and continue the following day. What steps do I need to take in to continue my work the following day?
regarding your question the things you want to make sure that whatever project you are working on (nodejs or react) that you cd into the project folder before you run any commands as these scripts you are running "npm run start" etc.. are based on what scripts are written inside the package.json.
so if you use create-react-app for reactjs the "npm run start" is a default script that comes with CRA and will run the app for you.
for express you can also check the scripts and there will be something similar but you can do "node server.js" (or app.js depends on how you called the file you initialize the server) and it will run the server.
in summary:
make sure to cd into the correct directory
check package.json for scripts if you are not sure what they are
also run "npm install" as you might have some missing dependencies
enjoy.
If you have any more questions will edit my response to answer those as well, have a nice day ;)
Just look for error messages in the Terminal when you run npm start. Try to understand them and fix them.
You can also install Nodemon (npm i nodemon) and run nodemon {filename}.js to start the server. {filename} is the name of the file in which you're starting the server.

How do I monitor symlinked modules with Nodemon?

I’m developing a module in Node.js which I’ve npm-linked into another projects node_modules folder. I’d like to restart this other projects server upon file changes in my module. Nodemon ignores node_modules by default, but I assumed I could override this using nodemon --watch node_modules/my_module – but can’t get it to work. If I temporarily remove node_modules from Nodemons lib/config/defaults.js it works, which probably confirms that the problem has to do with overriding default behavior.
Using nodemon 1.2.1, I'm able to do the following to get watches working with an npm link:
$ nodemon --watch . --watch $(realpath node_modules/my_module)
Basically...you have to watch the directory you're in (your project directory), and then specify a watch to the symlink itself. nodemon by default ignores node_modules, so explicitly specifying the watch fixes this. You may try updating your version of nodemon if this doesn't work for you.

sailsjs live update during serverside editing

It's annoying to have to restart the sails server when you change something, is there any way to make sailsjs do what meteor does where when you save a serverside file it automatically updates the clientside?
That's a pretty awesome feature, and I love sails but that feature is pretty cool.
Nodemon is a helpful development tool that watches the files in the directory that it was started in, and if anything changes are detected, your node.js application will automatically restart.
To install nodemon (you may need to use sudo)
$ npm install -g nodemon
Sails.js continually writes to the .tmp folder, and as a result you will find that nodemon will continually restart the server. To resolve this issue, simply ignore this folder by creating a .nodemonignore file with this single line, noting you can place any other files/folders you wish to ignore on separate lines
.tmp/*
To run your Sails.js application through nodemon
$ nodemon app
For more information, be sure to check out nodemon on npmjs.org
If you monitor nodemon --ignore 'tmp/*' --ext js,ejs . you will still get the infinite reload problem. Apparently Sails is constantly writing the ejs files.

How to make Nodejs pickup changes rather than restarting the server every time?

Is there a way for Nodejs to reflect the changes done in my files, rather than closing the node and running it again?
I'm still in the development phase so I make a lot of changes, so what I do is I stop the server each time and run it again (with "node" command)
I prefer to use https://github.com/remy/nodemon you can install it globally
npm install -g nodemon
and start your server by doing
nodemon app.js
You can use node-supervisor:
A little supervisor script for nodejs. It runs your program, and
watches for code changes, so you can have hot-code reloading-ish
behavior, without worrying about memory leaks and making sure you
clean up all the inter-module references, and without a whole new
require system.
You can use nodemon to monitor your files and will restart automatically when there is any changes:
npm install -g nodemon
after you can still use your command npm start but you will have to replace this line in package.json
"scripts":{
// "start": "node ./bin/www"
"start": "nodemon ./bin/www"
}

Resources