pm2-windows-startup stopped working after Windows reinstallation - javascript

I use PM2 module and pm2-windows-startup utility to automatically run Node.js when Windows startups. It was working perfectly during a few months, but recently once I reinstalled my Windows, the utility stopped working.
When I run Node by command promt with
pm2 start myapp.js --watch
I get the message
PM2 is being successfully deamonized
Then if I run the command
pm2-startup install
I get
Successfully added PM2 startup registry entry.
And then if I run
pm2 save
I get
PM2 is being successfully deamonized
Saving current process list...
Nothing to save !!!
But if I restart my computer, the utility doesn't start Node.js
How to resolve the problem?

Related

Running the server in Local Machine without showing cmd the window

I' ve created my node.js app with express, now i want to upload it on my local server machine.
I've created a bat file (I will use task planner to run this) that basically move to folder app and launch "npm run start".
The question is: There's a more correct way to this? (no cloud) and is it possible to hide the cmd window?
Putting a node.js application to production can be done with pm2. Pm2 will spin up your application and keep it alive, without having any terminal/cmd open.
Simply install pm2 globally on your machine:
$ npm install pm2 -g
Then launch your application with pm2:
$ pm2 start app.js
There are some configurations you could do, so I suggest you look at their repo

Node js server auto restart [duplicate]

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

How run Express Js/MongoDB in command line and close the terminal

I wanna know how can I run an express project but hide or close the terminal.
if I close the terminal my server fall, but I wanna hide it or something I'm doing a project in a local pc and me don't wanna that the user watches or close that and the app fall.
Use a process manager like PM2 or forever.
Forever example command: forever start app.js
Try using nohup <command>
sudo nohup npm start
A long version answer is to use docker-compose with node js and run services which works in the background by running:
docker-compose up -d <service_name>

PM2 not taking the latest version of nodejs installed

Previously, I had node version v0.10.46 installed on my ec2 server. For a recent project, I decided to give pm2 a try and installed pm2 using
npm install pm2 -g.
But, pm2 start index.js errored out since the project was using some ES6 syntax with arrow functions and let keyword.
Therefore, I updated the node version using nvm to latest v6.9.1, which is also the same version which we used for developing on local (windows).
However, pm2 start index.js again errored out with the same error:
pm2 show index hinted that the nodejs version was still not updated. I removed the old nodejs version, installed pm2 again, still of no avail.
I tried with other methods as well, by using:
pm2 start index.js --interpreter=~/.nvm/versions/node/v6.9.1/bin/node
to force pm2 to use the latest installed version of node. Every single try gave me the same errors with the same version of nodejs. Why is Pm2 not taking the latest version of node and sticking with 0.10.46?
If it helps:
which node
~/.nvm/versions/node/v6.9.1/bin/node
which pm2
~/.nvm/versions/node/v6.9.1/bin/pm2
Also, v0.10.46 was NOT installed using nvm.
Edit:
Here are the running pm2 daemons, using ps -ef | grep pm2:
Note that ec2-user is the logged in user and I also tried the same with root user. I installed nvm running node v6.9.1 and pm2 as root user as well with no success. I get the same error.
NVM allows you to run multiple version of node at a single time (between multiple shells). This means that when you run nvm use you are using that version of node within the context of that running shell.
Given PM2 runs as a daemon, I believe it kicks off its own process which is why it is not using the current nvm selected version.
This GitHub issue shows the usage of the interpreter flag which might be helpful for your specific issue https://github.com/Unitech/pm2/issues/1034
If the actual issue here is with the PM2 process needing to be running a specific NodeJS version, instead of an application PM2 is spawning, restarting the PM2 dameon itself after running the nvm use would have it startup with the current version of Node selected by nvm.

Cannot do actions in CMD bash when running server

I'm just starting to learn meteor.js. I used the command line to create a project and run it on my local server. However, when I do such a command as 'meteor' in my meteor folder, it starts running my server, but it disables to do anything further in command line. I can't type anymore or anything. What is wrong?
I'm running it on windows 8.

Categories

Resources