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
Related
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
In Visual Studio you can create a NodeJS console application, you can run and debug in Visual Studio.
I want to deploy it on a window server, beside with IIS, my IIS web application can invoke it through Jering.Javascript.NodeJS from my c# code(Asp.net):
StaticNodeJSService.InvokeFromFileAsync<string>("nodejs\app.js", args: new string[] {})
When I build the project in Visual Studio, the bin folder only has this file: Microsoft.NodejsTools.WebRole.dll, I have no idea what this file is for.
It works on my local, because I have nodejs runtime environment set up and all dependencies installed under npm.
Now I want to deploy it on server, one way to make it work on server is to copy all the project files into a folder and install all the dependencies through npm, If I have to do so, what the visual studio 'build' for?
we use pm2 to manage node js apps on windows
Install pm2 as windows service, use pm2 start to start your app
then you can call it in C# code through http or socket
I am writing a shell script that builds an angular app (ng build) and then runs a web server on the dist folder where angular bundles the app. The web server is run using the http-server command. (http-server just like npm needs to be installed globally in my server so the script can be run successfully.)
For some reason, I want to copy the angular source code into another server and execute the script there. I can't tell if npm/ng and http-server are installed on the other server.
If I try to install them automatically from the script (for example: npm install --global http-server) would root/admin be an issue here ?
You can't use package if it is not installed.
And no, it does not require an admin permission if you are installing this package locally in your project.
If you want to install your package globally, then you will need the admin permission.
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>
We do not want to require our clients to install node.js on their Mac or Windows machines. We would like our clients to run an installer that would install a windows or mac service. The service, when started, would start the node executable from the install directory (basically run ‘node server.js’ with node.exe included in the install) and then monitor that node application and restart it if the service dies. (We are using window-node and windows-mac now but they require node.js to be installed first.) Does anyone know how to do this?