I'm using nodemon with babel-node in development environment.
I'm working on Windows 7 and every time I change my code, nodemon restart multiple times.
I searched on google and even in stackoverflow and github, the temporary solution is just: re-install nodemon: npm i -g nodemon. But after some minutes, the problem come back :(
I tried add --delay sometime and even re-install node.js but it does not work
How can I fix that? This problem slow down my work :(
if you mean restart by this
then here is your answer
we use nodemon for this work
nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected. nodemon does not require any additional changes to your code or method of development.
have a look at nodemon docs
if not then
look at this answer
Related
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.
I have a React app with Node as the server and I am writing my code in ES6 and transpiled using babel. I am using Windows OS. I was using NodeMon for watching changes it worked fine in development. I am making a production configuration for the app and thought of using PM2 for both dev and prod.
Below is the script in my package.json,
"scripts": {
"dev": "pm2 start --watch --interpreter babel-node src/server/server.js --name appDev",
...
"prod": "pm2 start build/server/server.js -i max --name appProd"
}
I have ES6 code in my src folder and transpiled ES5 code in build folder. "prod" command works fine if I remove "-i max" [infinite command prompts started opening up with "-i max". Hope it will be fine in server after deployment].
Now the problem is, "dev" script is always resulting in "errored" status and when I check status error logs are empty.
ANy idea what's going on? I will run NodeMon in dev and PM2 in prod for now but why PM2 has issue with ES6 and --interpreter babel-node?
Update:
I have tried --interpreter babel-cli after installing globally, it failed with an error [PM2][ERROR] Interpreter babel-cli does not seem to be available. I have babel-cli globally and locally.
Even pm2 start app.js --interpreter ./node_modules/.bin/babel-node didn't work.
I had issues deploying with the latest (12.16.2) version of node. I was having issues with ES6 and imports. I understand there are more complex solutions that can solve that issue, but backing up to node 12.4.0 solved that issue for me. NOTE: Node 12.4.0 is an earlier release than 12.16.2. I picked version 12.4.0 because that is what Digital Oceans "Node" servers are initialized with. I figured that their server guys probably know far more about it than I, and just decided to cheat off their test, so to speak.
I am having no issues with 12.4.0, and you can easily download an earlier version off of the node website. If you plan to install it on a Linux server, I would recommend using nvm. I had used nvm to go back to 12.4.0, and still had issues (I am sorry I forget specifics). I just redid the server from a fresh image with plain Ubuntu 18.04 LTS and am good on that at this time. Even with the local Windows install of node that I use to develop, I had to do a full uninstall and a clean install to avoid issues. Highly recommend this route if able.
Good luck.
I am running a node.js application in Windows and I want to make it automatically restart if there is an unhandled exception in the code which causes the application to stop.
I have done some research and I found that a combination "Forever" and "Nodemon" can achieve this goal.
I installed both packages globally on my Windows 10 Device.
npm install forever -g
npm install -g nodemon
I tried using the following command to launch my app:
forever start nodemon --exitcrash app.js
However, I get the following error: "nodemon does not exist"
If try just running "nodemon" the application starts which indicates the Nodemon package is installed however, this will not allow the app to restart after a crash.
Am I doing something wrong? Most advice I find online is only relevant to Linux systems.
If you are already using forever, then you can get rid of nodemon. Instead you can use a combination of forever and cluster module. Simply fork the worker in case of exceptions, and it makes your app more scalable too!
If still nodemon is preferable, maybe try installing it globally using the -g flag
Forever and nodemon achieve 2 completely different objectives
nodemon is used to run your application in development mode, where you are frequently changing code, and need to restart the server .It will not restart your application in case of a crash. more about that later
Forever, on the other hand, is for making your application run as a daemon in production. And auto restart if you have uncaught exceptions.
Historically people have used Forever stand alone, or with upstart scripts, running as a linux service one of the most famous being upstart
Current norm is to use PM2
I've recently reinstalled node package manager npm install nodemon -g which grabbed the latest build. But when I run nodemon server.js and I save changes to files, it's extremely slow to restart the server. It might take 10-30 seconds to detect file changes and when the restart process executes, it can take a few seconds to finish. I'm using nodemon 1.17.3. I don't have this problem on my other build (same PC and same local parent directory) that's using nodemon 1.14.8. Has anyone else experienced this?
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.