Run NodeJS server from AWS EC2 - node.js

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?

Related

dev uncaught exception: listen EADDRINUSE: address already in use :::5000

I am getting the above error
[nodemon] starting `ts-node index.ts`
dev uncaught exception: listen EADDRINUSE: address already in use :::5000 +0ms
[nodemon] app crashed - waiting for file changes before starting...
I tried to find the pid with sudo lsof -i :5000
then kill -9
But then a new process pops up at the same port again. It keeps happening infinitely so I found the parent process with pid 1 and killed it and laptop restarted.
I am unable to run my node app on 5000. Any suggestions?
Edit: My repo is a node app at the root level and has a client folder which is the react app.

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

How to fix Nodemon exit on changes issue

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.

Resources