How to fix Nodemon exit on changes issue - linux

everyone. I like to use nodemon while developing with node.js because its restart on changes feature. I never had any problem at all. But since I updated Ubuntu from 13.04 to 13.10 it fails to restart on every change I make, so I have to restart my server manually. I run my apps as always, like so:
nodemon app.js
and with some config options like:
nodemon app.js production
The problem is, like I said, that even if the file I'm modifying is a client side one, I happen to get:
9 Nov 13:48:29 - [nodemon] v0.7.10
9 Nov 13:48:29 - [nodemon] to restart at any time, enter `rs`
9 Nov 13:48:29 - [nodemon] watching: /home/alevardi/render/wip/paraiso
9 Nov 13:48:29 - [nodemon] starting `node app.js`
Express server listening on port 3000
Successfully connected to MongoDB
9 Nov 13:48:51 - [nodemon] exiting
The last line of the output above, appears when I change a file. So, what can i do for fixing this awful issue? It is driving me crazy!
NOTE: I've tried with Forever and supervisor with the same results.
Thanks a lot for your help.

Related

Run NodeJS server from AWS EC2

EC2 is properly deployed with my NodeJS server but I can't figure out how to keep it running without an ssh connection to the linux machine and running npm start
For Example:
[ec2-user#ip-172-31-89-105 me_server]$ npm start
> me-server#1.0.0 start
> nodemon index.js
[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Server Started at 8080
Database Connected
I can run this command from an ssh tunnel from my local machine but I don't want my local machine to be in control of the server connection, how can I tell EC2 to run npm start on its own and keep it running indefinitely?

Dev Server restart repeatedly results in: code: 'EADDRINUSE'

I find myself having to cycle through the following pattern in terminal while using nodemon:
Emitted 'error' event at:
at emitErrorNT (net.js:1253:8)
at processTicksAndRejections (internal/process/task_queues.js:84:9) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8081
}
[nodemon] app crashed - waiting for file changes before starting...
^C
owner#G700:~/PhpstormProjects/shopify/from_tch$ sudo lsof -i :8081
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 28169 owner 19u IPv6 26913489 0t0 TCP *:tproxy (LISTEN)
owner#G700:~/PhpstormProjects/shopify/from_scratch$ kill -9 28169
owner#G700:~/PhpstormProjects/shopify/from_scratch$ nodemon server.js
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
> Ready on http://localhost:8081
nodemon is supposed to handle restarting the server on changes, so I'm not sure why it seems to keep conflicting with itself and forcing me to kill processes. Does anyone know if this is a misconfiguration, or how to overcome this? I'm on Lubuntu 18.04 and my terminal is this:
$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

App crashed in nodemon

I am trying to run in debug mode using Git Bash a nodejs application.
I did it several times but on the recent ones it doesn't work anymore.
When I run the command:
npm run startwindows:inspect
it says:
14 Apr 15:10:59 - [nodemon] v1.4.1
14 Apr 15:10:59 - [nodemon] to restart at any time, enter `rs`
14 Apr 15:10:59 - [nodemon] ignoring: C:\XXX\.git/**/* C:\XXX\node_modules/**/* C:\XXX\bower_components/**/* .sass-cache
14 Apr 15:10:59 - [nodemon] watching: C:\XXX\server/**/* C:\XXX\config-local/**/*
14 Apr 15:10:59 - [nodemon] watching extensions: js,json,yaml
14 Apr 15:10:59 - [nodemon] starting `node --inspect --debug-brk energyreports.js`
14 Apr 15:10:59 - [nodemon] child pid: 6352
Unable to open devtools socket: address already in use
14 Apr 15:10:59 - [nodemon] app crashed - waiting for file changes before starting...
14 Apr 15:11:03 - [nodemon] watching 37,149 files
14 Apr 15:11:03 - [nodemon] watching 37,149 files - this might cause high cpu usage. To reduce use "--watch".
What can I provide more is that startwindows:inspect is a script from the package.json file and it looks like this:
"startwindows:inspect":"set NODE_ENV=dus&& set NODE_CONFIG_DIR=./config-local/&& nodemon -V -w server -w config-local -e js,json,yaml --inspect --debug-brk| bunyan -o short"
What means by using --watch? Is this a normal case when testing it in debug? My CPU % utilization looks fine all the time.
Well it says exactly what the problem is.
Unable to open devtools socket: address already in use
Previous instance of the app is still running. Just restart your computer or kill related running processes.
New Edit: By OwlyMoly
Killing processes at a particular port: (In Mac)
If you know the port where your app running at, then check for that port ID and kill the process.
To check port id:
lsof -i :YourPort
or
lsof -n -iTCP:YourPort | grep LISTEN
Then get PID from the result and use the below command to kill that process.
To Kill process using PID:
kill -9 PID

Nodemon doesn't restart

I have a nodemon running in a docker-container with a mounted volume on OSX. Nodemon is receiving the file-change but it doesn't restart the server.
Output:
Creating piclet_web_1...
Attaching to piclet_web_1
web_1 | 7 Sep 13:37:19 - [nodemon] v1.4.1
web_1 | 7 Sep 13:37:19 - [nodemon] to restart at any time, enter `rs`
web_1 | 7 Sep 13:37:19 - [nodemon] watching: *.*
web_1 | 7 Sep 13:37:19 - [nodemon] starting node ./index.js
web_1 | restify listening at http://[::]:80 //normal output of started node-app
//file-change, which gets detected
web_1 | 7 Sep 13:37:30 - [nodemon] restarting due to changes...
//no output of restarted server
Dockerfile:
FROM node:0.12.7-wheezy
EXPOSE 80
RUN npm install nodemon -g
ADD app /app
WORKDIR app
RUN npm install
docker-compose.yml
web:
build: .
ports:
- "80:80"
volumes:
- ./app/lib:/app/lib
links:
- db
command: "nodemon -L ./index.js"
db:
image: mongo:3.1.7
I solved the issue by choosing another base-image for the container: node:0.12.7 instead of node:0.12.7-wheezy

Node.js stopped with "Sending SIGTERM to child" for no reason

This problem is pretty much the same issue posted on https://www.openshift.com/forums/openshift/nodejs-process-stopping-for-no-reason. Unfortunately it remains unanswered.
Today my Node.js app stopped few times with DEBUG: Sending SIGTERM to child... on the logfile. No more, no less. My application is a very simple single-page app with single AJAX endpoint, serving 1k-2k pageviews per day. It has been running well for days without any problem.
I use these modules:
express
body-parser
request
cheerio
-- Update:
I'm using one small gear. 512MB mem, 1 GB storage
Excerpts from log file (~/app-root/logs/nodejs.log)
Thu Jul 17 2014 09:12:52 GMT-0400 (EDT) <redacted app log message>
Thu Jul 17 2014 09:13:09 GMT-0400 (EDT) <redacted app log message>
Thu Jul 17 2014 09:14:33 GMT-0400 (EDT) <redacted app log message>
DEBUG: Sending SIGTERM to child...
#### below are the log entries after issuing "ctl_app restart"
DEBUG: Running node-supervisor with
DEBUG: program 'server.js'
DEBUG: --watch '/var/lib/openshift/redacted/app-root/data/.nodewatch'
DEBUG: --ignore 'undefined'
DEBUG: --extensions 'node|js|coffee'
DEBUG: --exec 'node'
DEBUG: Starting child process with 'node server.js'
Stats from oo-cgroup-read, as suggested by #niharvey. A bit too long, so I put it on http://pastebin.com/c31gCHGZ. Apparently I use too much memory: memory.failcnt 40583. I suppose Node.js is automatically (?) restarted on memory overusage events, but in this case it's not. I had to restart manually.
I forgot that I have an idle MySQL cartridge installed, now removed.
-- Update #2
The app crashed again just now. Value of memory.failcnt stays same (full stats on http://pastebin.com/LqbBVpV9), so it's not memory problem (?). But there are differences in the log file. The app seems restarted, but failed. After ctl_app restart it works as intented.
Thu Jul 17 2014 22:14:46 GMT-0400 (EDT) <redacted app log message>
Thu Jul 17 2014 22:15:03 GMT-0400 (EDT) <redacted app log message>
DEBUG: Sending SIGTERM to child...
==> app-root/logs/nodejs.log-20140714113010 <==
at Function.Module.runMain (module.js:497:10)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
module.js:340
throw err;
^
Error: Cannot find module 'body-parser'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
To simulate this problem on your local machine run your server with supervisor in one terminal window:
supervisor server.js
Then from another terminal use the kill command
kill process_id#
The kill command with no parameters sends a SIGTERM message to the application. If supervisor receives a SIGTERM it will stop immediately.
The sample code from the sample application provided by OpenShift listens to 12 different unix signals and exits. It could be that someone at OpenShift is manually killing the process because the application is not listening to a signal that was intended to reboot it. I'm adding this code to my application to see if the behavior is more stable.
function terminator(sig){
if (typeof sig === "string") {
console.log('%s: Received %s - terminating sample app ...',
Date(Date.now()), sig);
process.exit(1);
}
console.log('%s: Node server stopped.', Date(Date.now()) );
};
process.on('exit', function() { terminator(); });
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
].forEach(function(element, index, array) {
process.on(element, function() { terminator(element); });
});
Usually this is because your app became idle. When you ssh into the app you should see something like:
*** This gear has been temporarily unidled. To keep it active, access
*** your app # http://abc.rhcloud.com/
You can try to use a scheduled ping to keep the app alive.
I had this same issue. I deleted the gear and created a new one. The new one has been running for a few days and doesn't seem to have the issue.
[Update]
After a few days, the issue appeared on my new gear.

Resources