I have a pretty basic nodemon configuration. I'm fixing this legacy node 7 project that I inherited and trying to make the development process a little bit painful. First thing first, a proper restart-and-transpile process (since it's built using ES6 modules syntax).
This is my folder structure:
- src
|- index.js
- dist
|- index.js
- index.js
- nodemon.js
I run nodemon as "start:dev": "nodemon index.js"
Here's it's content:
// index.js
if (process.env.NODE_ENV === 'production') {
require('./dist/index.js');
} else {
require('babel-register')({});
require('babel-polyfill');
require('./src/index.js');
}
The idea is that the code is transpiled on runtime, so that I don't have to stop server, re-transpile, start server manually, as I have been doing before.
Last but not least, nodemon config
// nodemon.js
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules"
],
"verbose": true,
"watch": [
"src"
],
"env": {
"NODE_ENV": "development"
},
"ext": "js json"
}
I took this setup from MERN, and I think it should work. However, when I made a change and save, it goes:
[nodemon] files triggering change check: src/index.js
[nodemon] matched rule: /Users/me/project/path/src/**/*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] src/index.js
(stuck here. it never restarts)
I've been checking the code, and the only thing that I'm unfamiliar with, that maybe be causing it I can think of would be a child_process.execFileSync()
call, that will call a java tool; and a connection pool with mysql.createPool()
(mysql
package).
Tried both in Node 7.5 and Node 8.9. Any idea of what could be wrong?
Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.
If you get the error "nodemon cannot be loaded because running scripts is disabled on this system", open your PowerShell as an administrator and set its execution policy with the Set-ExecutionPolicy command. Copied! Make sure to open your PowerShell as an administrator before you run the Set-ExecutionPolicy command.
You can restart the process at any time by typing rs and hitting ENTER . Once you make the changes to package. json , you can then call nodemon to start the example app in watch mode without having to pass in server.
js Automatic restart Node. js server with nodemon. In this case, if we make any changes to the project then we will have to restart the server by killing it using CTRL+C and then typing the same command again.
For those who still do not have an answer, I reinstall an older version and it works
like "npm i -g [email protected]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With