I'm currently using node along with nodemon. Then I got to thinking it might be sometimes nice to use an inspector with node so have started using node-inspector
However, is it possible to run both at the same time?
Normally to run nodemon I would use:
nodemon server.js
//and similarly
node-debug server.js
I have also tried:
nodemon --debug http.js
But sadly this didn't work either.
But both together!?
If you want to run them as one command this works for me: node-inspector & nodemon --debug app.js (replacing app.js with the name of your script). If things get all mucked up you will occasionally have to kill node-inspector manually, but running the command this way gives you the option of running rs to restart nodemon manually if needed. HTH
You would start your server with nodemon --debug server.js and then you'll need to run node-inspector in a separate terminal window unless you push nodemon to the background.
For those that want an OS-independent solution and no hacks for windows, etc.
You can use npm-run-all which is a CLI tool that allows running multiple npm scripts in parallel or sequentially. So you'd set your package.json as so:
"scripts": {
"start": "npm-run-all --parallel lint start:debug start:server",
"lint": "eslint . --ext .js",
"start:debug": "node-debug server.js",
"start:server": "nodemon server.js"
}
And then from CLI, you do: npm start
Caveat: from my experience running nodemon and node-debug together leads to weird node-inspector behaviors sometimes. So i've since opted to remove nodemon from my scripts when debugging and relying on node-inspectors save-live-edit feature to change files on the fly.
I could not get nodemon to play nice with node-inspector. After one change it would restart but after that no more. Maybe it is because I am using docker containers.
The easiest way to reload the application is to let node-inspector do it (I know this is not an answer to having both run but it worked for me).
Start your application in the following way:
node-inspector --save-live-edit & \
node --debug /app/server.js
As I'm running on Linux I wrote a bash script based from rpaskett's answer so that you don't need to remember that awkward command every time.
However I noticed in a comment you're running Windows. Here are some options you have:
You could convert the bash script to Windows batch and save it as C:\Windows\System32\node-DEV.bat. I did it and it works on my Windows PC:
#echo off
echo Starting DEV environment for %1
start node-inspector
nodemon --debug %1
Then you should be able to run node-DEV server.js.
Another option; you could run something like nodedev which was written in Node.js thus platform independent, although it looks like it hasn't been updated in a while.
Or you could even run the bash script within a Cygwin environment if you had one handy.
A hacky fix for Windows users running a bash shell:
First, add node-inspector to your Path.
(You can find where npm is installing packages with npm list -g)
Then use this command in bash, or add it to your npm scripts:
START /B node-inspector && nodemon --debug server.js
START /B being the windows command to run in the background.
You must be install node-inspector and nodemon using:
npm install -g nodemon
npm install -g node-inspector
To run in Windows, make a new .bat file and add the folowing lines:
#echo off
echo Starting developer enviroment of the file %1
start nodemon --debug-brk %1
node-debug %1
And run:
node_desarrollo.bat "name of the file to run.js"
If ran with a error:
Error: listen EADDRINUSE :::5858
at Object.exports._errnoException (util.js:855:11)
at exports._exceptionWithHostPort (util.js:878:20)
at Agent.Server._listen2 (net.js:1237:14)
at listen (net.js:1273:10)
at Agent.Server.listen (net.js:1369:5)
at Object.start (_debug_agent.js:21:9)
at startup (node.js:72:9)
at node.js:980:3
Its normal because the node-inspector need to open that port to connect but because the nodemon --debug-brk %1 was opened the 5858 port its cannot open and show the EADDRINUSE :::5858 error, note that the flag --debug-brk of nodemon it's necessary to make a breakpoint on the first line. Try modifying the file.js after run the .bat and look the changes reflected on the debugger. This debugger reboots and show the changes done in the file.js. Happy coding JS!!!
{
"scripts": {
"dev": "npx nodemon --exec \"node --inspect --debug-port=0.0.0.0 src/index.js\""
}
}
Related
I've always used just npm and never yarn/webpack explicitly. I need to run the code from this repo:
https://github.com/looker-open-source/custom_visualizations_v2
Like a dev server or something to ensure it's serving the files properly but I don't see a "run" like npm run start. Does this just not exist with yarn? It feels like this code should work as is and I shouldn't have to add anything.
EDIT: I've now tried yarn run watch but it just seems to build the code again and not actually host anywhere
npm run somecommand just looks up in the "scripts" field of package.json for the key
somecommand and executes the value in the terminal.
So npm run start basically runs the start script from package.json
The same thing is done using yarn via simply yarn start
In the linked repo, there isn't a start script in the package.json, rather a watch script, so you should be able to run it with the below steps:
yarn to install dependencies after cloning the repo to local (similar to npm install)
yarn watch to start the webpack server (analogous to npm run watch)
Edit:
Turns out the watch command is just setting up webpack to watch for changes and recompile the project every time there is a change.
To run a development server, you will need to add another script preferably with name start and use webpack-dev-server
So the package.json has entries like:
...
"watch": "webpack --config webpack.config.js --watch --progress",
"start": "webpack-dev-server --config webpack.config.js",
...
Then running yarn start should open a dev server at localhost:8080
Screenshot form VS code terminalnodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the
path is correct and try again.
I just meet that question.
First, you should make sure that you had installed nodemon in a global way (npm install -g nodemon), and make sure global package dir is in the environment variables.
Secondly, you should RESTART VScode if you are opening it now.
I spent lots of time to make sure the previous one, but it still fails, then when I restart VScode, everything is fine!
Try to install nodemon globally:
https://github.com/remy/nodemon
npm install -g nodemon
and edit Your package.json for example like that:
"scripts": {
"start": "node server",
"dev": "nodemon server"
},
then in terminal enter the command =>
npm run dev
It should works for You now ;-)
Good Luck and Best regards !
Below are some solutions
This is how you can install nodemon
npm install -g nodemon
after that you have to run this command: npm run dev
here dev is (script) server name like
{
"main": "app.js",
"scripts": {
"dev": "nodemon app.js"
},
}
after that if you are facing error like
" 'nodemon' is not recognized as an internal or external command,
operable program or batch file. "
Then after install nodemon globally write below command:
npm config get prefix
in output you will get PATH and then past this path in to the Environment Variables and it solved
Restart the terminal and run this command
nodemon run dev
I hope after that it will work properly :)
I just had to use npx instead of npm
for e.g. - npx nodemon <server.js>
I'm going to run react-boilerplate application forever in the server.
I found forever and I'm not sure how I pass parameters to forever. The command to run server is like following:
PORT=80 npm run start:production
Seems like forever start PORT=80 npm run start:production doesn't help me.
One thing is that PORT=80 part is setting the env variable, this kind of command should be in front of other commands. The other thing is that to run npm scripts with forever, you need to use different syntax, so PORT=80 forever start -c "npm run start:production" /path/to/app/dir/.
If you're running forever form the project folder, the path should be ./
Or you can run a react application with pm2 or with nohup
1) install pm2 globally
npm install pm2 -g
2) navigate to the project folder and execute, space is required after --
pm2 start npm -- start
3) to see running instances
pm2 ps
4) to see the other options
pm2 --help
To run with nohup
1) navigate to the project folder
nohup bash -c 'npm start' &
pm2 is superb production process manager for Node. In addition to starting and daemonizing any application, it has a built in load balancer.
Install pm2:
npm install pm2 -g
To add start and add deamon to your app, navigate to the app folder and:
pm2 start app.js
To make pm2 autoboot on server restart:
$ pm2 startup
Then copy and paste the code generated.
For this you will need:
Install forever usingnpm install -g forever
Run the forever command PORT=<YOUR PORT> forever start -c "<command>" ./
Your command can be for example npm start and npm run dev.
Use ./ only if you are in the project folder.
Port means your port number, usually 80 or 443.
Running nodemon --inspect index.js or nodemon --debug index.js doesn't work.
Node Version : 8.9.1
Nodemon Version : 1.12.6
I have tried these with no luck :
nodemon --inspect-brk index.js
nodemon -- --inspect index.js
nodemon index.js -- --inspect index.js
nodemon index.js -- --debug index.js
nodemon -- --debug index.js
nodemon --inspect --debug index.js
nodemon --debug-brk index.js
But node --inspect index.js or node --inspect-brk index.js works. I wonder how? If any alternatives or some kinda workaround would be great too.
Please comment if you need further description.
For people coming from search engines, there could be a bug related to nodemon and ts-node.
Error: Unknown or unexpected option: --inspect
This can be a way to use inspect with nodemon:
nodemon --exec 'node --inspect=0.0.0.0:9229 --require ts-node/register src/index.ts'
For more information see here
SOLVED,
It seems like nodemon#1.12.6 was not passing in this argument. There is a newer version available 1.12.7 where everything works fine and well.
Answer source: Nodemon Issues - Github
nodemon --inspect app.js
The .js part is absolutely necessary.
FINALLY SOLVED
Just follow the below steps are you're good to go:
Make sure you have updated version of nodemon. Update is using following command: npm i nodemon#2.0.4 -g. Make sure to use -g(to give nodemon permissions to run as an administrator). If you get some warnings, try running the same with sudo command sudo npm i nodemon#2.0.4 -g
Then execute the command as: nodemon --inspect app.js
I hope it helped..!!
for anyone who is having error ARG_UNKNOWN_OPTION specially with typescript ts-nod and when using auto attach debugger in vscode
example with other arguments like dotenv
nodemon -r dotenv/config ./src/index.ts -- --inspect
As per official doc Nodemon NPM
You can also pass the inspect flag to node through the command line as you would normally:
nodemon --inspect ./server.js 80
I just installed Node.js on my Ubuntu 14.04 operating system for the first time. I also installed npm. The next step in my installation process was installing nodemon. This all worked out fine.
But, when I run nodemon by typing nodemon app.js in my command line, I get the following error...
[nodemon] 1.8.1
[nodemon] to restart at any time, enterrs
[nodemon] watching: *.*
[nodemon] startingnode app.js
[nodemon] Internal watch failed: watch ENOSPC
In the command line below the error...
alopex#Alopex:~/Desktop/coding_dojo/week-9/javascript/node/testing_node$ Hello World
Why is this happening? Is this normal behavior for nodemon? If not, how can I fix it?
Side notes...
1) app.js is a Javascript file with console.log(111) inside of it.
2) node version is v0.10.25
3) npm version is 1.3.10
4) nodemon version is 1.8.1
5) ubuntu version is...
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty
It appears that my max ports weren't configured correctly. I ran the following code and it worked...
echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
What this command does is to increase the number of watches allowed for a single user. By the default the number can be low (8192 for example). When nodemon tries to watch large numbers of directories for changes it has to create several watches, which can surpass that limit.
You could also solve this problem by:
sudo sysctl fs.inotify.max_user_watches=582222 && sudo sysctl -p
But the way it was written first will make this change permanent.
On running node server shows Following Errors and solutions:
nodemon server.js
[nodemon] 1.17.2
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node server.js
[nodemon] Internal watch failed: watch /home/aurum304/jin ENOSPC
sudo pkill -f node
or
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Erik,
You can just kill all the other node processes by
pkill -f node
and then restart your server again. It'll work just fine then.
As per discussion over here, ENOSPC means Error No more hard-disk space available. Reason why this much memory required by nodemon or gulp-nodemon (in my case) is that it was watching contents of a folder which it shouldn't. To fix that nodemon has ignore setting that can be used to tell nodemon what not to watch. Have a look at nodemon sample config here.
[nodemon] Internal watch failed: watch /home/Document/nmmExpressServer/bin ENOSPC
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nmmexpressserver#0.0.0 start: `nodemon ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nmmexpressserver#0.0.0 start script.
This is the error I got when running nodemon ./bin/www.
The solution was closing an Atom window that had a entire directory of folders open in the project window.
I don't know why, but I'm assuming Atom and nodemon use similar processes to watch files/folders.
Add a nodemon.json configuration file in your root folder and specify ignore patterns for example:
nodemon.json
{
"ignore": [
"*.test.js",
"dist/*"
]
}
Note that by default .git, node_modules, bower_components, .nyc_output, coverage and .sass-cache are ignored so you don't need to add them to your configuration.
Explanation: This error happens because you exceeded the max number of watchers allowed by your system (i.e. nodemon has no more disk space to watch all the files - which probably means you are watching not important files). So you ignore non-important files that you don't care about changes in them for example the build output or the test cases.
in my case closing the visual studio code then starting the server did the trick
Operating system - ubuntu 16.4 lts
node.js version - 8.11.1
npm version - 6.0.0
Instead of specifying a list of directories to ignore (e.g. negative), you can also specify a list of directories to watch (e.g positive):
nodemon --watch dir1 --watch dir2 dir1/examples/index.js
In my particular case, I had one directory I wanted to watch and about nine I wanted to ignore, so specifying '--watch' was much simpler than specifying '--ignore'
There must be a better way of solving this, than what I suggest. I hope some experts land on this page. Also note that I was working on a development server and thus could afford to kill all processes of node. This may not be what you want.
I followed the answer of #zubair-alam and got it fixed for the first time. I added the "ignore" to the package.json (Even though the referred link says it is the default).
........ Before
"ignore": [
".git",
"node_modules/**/node_modules"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon ./index.js --exec babel-node -e js"
},
........ After
However the error returned again as soon as I added a new file to the folder. I was working on Linux, so I basically killed all process related to node, by saying the following.
killall node
and then restarted npm by saying. The server started without errors.
npm start
You will have to change the killall command using a command specific to your operating system. See this discussion.
I had the same error, but in Ubuntu 14.04 inside Windows 10 (Bash on Ubuntu on Windows). All I did to overcome the error was to update the Creators update, which then allowed me to install 16.04 version of Ubuntu bash and then after installing newest version of node (by this steps) I installed also the newest version of npm and then the nodemon started to work properly.
Try reopening VS code or Atom with more specific directory where your app.js is present.
I had a lot of folders opened and this problem occured. But once I opened my specific folder and tried once again, it worked.