I am building a web application and would like to run 3 different commands.
run mongodb
Run react-scripts to build/watch react app.
Run express server.
I can do this individually in different terminal sessions, but would it be possible to run these with 1 command using something such as pm2? (I know it's only meant for production usecase but for this is it overkill?) Or would something like a docker container work?
Sorry if this is an awful question. But I am at a loss at what I should actually be looking for!
Thanks,
Related
I have a project with 5 microservices on nestjs and it takes a very long time to run each one manually. I have a main microservice, when I start it, I want the rest of the microservices to start. How should I do it? If there are similar options, please suggest
I think there is not an official way to do it. I use this library concurrently. Then you can do something like:
concurrently "yarn run start:api-gateway:dev" "yarn run start:identity:dev"
And you will see all logs in the same terminal window.
I know to start my Node app I type in the Win shell, node app.js.
But this is obviously not how a webhost would maintain a Node webserver (ie what happens if there is a power outage, a Node exception, etc).
I see things like Forever and running Node as a Windows service, but I feel like the creator of Node must have had a different idea? Something like Apache is installed as a Windows Service so that it runs even if the server reboots - what is the correct method of doing this for Node? I don't like the idea of introducing another piece of software just to keep the server going.
Thanks.
The problem is that many systems do not do that. For instance MongoDB doesn't even run like that on windows.
The best solution I have found is this https://nssm.cc/
Also you have to consider even on Linux you need to run something like upstart to keep node programs running when you close the console.
I am running a Node.JS + Angular JS application on a cloud server using the MEAN stack. The application is terminating every hour or sooner.
I have few thoughts and would like someone who can tell me which might a cause.
I am using SSH through root when I start the service using this command
NODE_ENV=production PORT=80 grunt serve:dist
Do I need forever to run this properly ?
Should I use a server user (similar to apache) that can run the application?
If yes how do I do this ?
We do not have a deployment engineer in our team but it is annoying to not being able to keep the app running on the server after developing the application. Please help diagnose the problem.
If you don't want to use a deployment service — MS azure, AWS, heroku, etc. (which would probably be a lot easier) — then yes, you would have to use something like forever to restart your sever every time it crashes. It's really odd that your app terminates after an hour though, it'd be helpful if you could describe why that's happening.
I have multiple node.js apps running at my VPS, and I access to it through ssh. Right now I start them in the way:
nohup node server.js
That looks good but I get whole logs to nohup.out, and what's more important and not efficient is about restarting of stopping them.
If I do ps -A | grep node I will get an output like:
9172 ? 00:00:01 node
9178 ? 00:00:00 node
...
So, how can I identify them?
I also knew about nodemon and it's great! But however logging out ssh breaks the magic.
I think maybe some more advanced tools would help out. What's the best approach for this?
Just in case, I use Nginx on top (port 80) and do reverse proxy, but I'd be ok changing that.
One solution (there are many) is pm2: https://github.com/Unitech/pm2
It's a process manager for node, and comes with a variety of features, some of which include the ability to spread your app across multiple CPU cores while providing an easy TTY management view of the applications. It also has the ability to reload the apps without stopping them.
If the readme's not sufficient, I found this post useful in understanding the basics: http://devo.ps/blog/2013/06/26/goodbye-node-forever-hello-pm2.html
You can run nodemon under --quiet mode and it'll suppress all nodemon output (and keep your logging working).
I'm working through the StrongLoop's getting started instructions and created my sample app. Whilst the instructions tell me to use:
slc run .
to start my application, I noticed I can equally run my application with:
node app.js
and get the same result. Obviously by using the second approach I can integrated my StrongLoop application with tools such as forever.
So my question is, what extra benefits does slc run offer? Does it have functionalities such auto restart etc?
You can do more with slc than node app.js.
slc is a command line tool for StrongLoop, which has more features. If you just want to run the app, it doesn't matter much, but if you want to do more, you can.
Here's the documentation: http://docs.strongloop.com/display/SLC/StrongLoop+Controller
It doesn't have much features for development (such as auto restart and such), but it will help with managing servers and what not.
My favorite feature is scaling a node app using slc.
You can do "slc run . size 2". This will spin up 1 master and 1 worker process which is part of a single cluster. Now if my workload increases, and resources are low, which I know using strongOps monitoring (slc strongops) and I want to scale the app without having to stop the app and re-engineer, I can just do the following:
"slc clusterctl size 4". This will spin up 2 more worker processes and automatically attach them to the same application cluster at run-time. The master will auto distribute the workload now to the new processes.
This is built on top of node cluster module. But there is much more to it. Used cluster-store to store shared cluster state objects too.
Another feature is "slc debug". Launches Node Inspector and brings the application code in runtime context and helps me in debugging, load source maps and iterate through test runs.
Based on the latest release at the moment (v2.1.1), the main immediate benefit of running slc run instead of node app.js is you get a REPL at the same time (lib/run-reple.js#L150L24). Looks like all you have to do is have main set properly in package.json, since it uses Module._load().
If you run slc run app.js you get no benefit as far as I can tell: lib/commands/run.js#30.
Yay open source! https://github.com/strongloop/strong-cli
One of my favorite features is 'slc debug app.js' which brings up node-inspector for debugging . its nice CLI sugar. But of course you can totally run node and configure this manually.
I created a Linux init.d Daemon script which you can use to run your app with slc as service:
https://gist.github.com/gurdotan/23311a236fc65dc212da
Might be useful to some of you.
slc run
it can be only used for strong loop application
while node . or node [fileName]
can be used to execute any Nodejs file