I am trying to set up a node.js server. On my Mac, I can start and stop the app in terminal like:
start=
node app.js
stop=
CTR-c
I also have the same node setup on my linux server website.
I try to do the same start and stop in the terminal the same way on the linux server but I can't seem to stop it with CTR-c even though it looks like it did work.
The app keeps running.
My goal is to to be able to make edits / mods to the webserver node app. I think we have to stop and start to update the changes - but it does not seem to be working.
I know a bit about nodemon - but do not know if it should be used on live production servers?
Q: How do I make changes to the linux server app and get them to show up like they do in MacOS?
Related
I have a sailsjs app on AWS EC2, which I have been running till now using forever. I have two adantages using forever:
1) Perpetuality: I can use the CLI forever start app.js or forever restart app.js and then app starts running and keeps on running till I stop it with the command forever stop app.js. So, the app does not stop even when I close my terminal. The process keeps on running.
2) Runtime Log: I have a .forever directory that has a log file, while on real time records the server logs, and when I check the log using tail -f file_name.log, I get to see run time logs.
However there is a disadvantage: Every time I upload a new/modified server file, I have to restart the app manually. To get rid of this, I am switching from forever to nodemon.
From the documentation provided by Nodemon, I cant figure out how can I replicate the two advantages, as mentioned above, from Nodemon too. Will be a great help if anyone can guide me on how to start my nodejs app using nodemon so that it can keep running even after closing the terminal on my side, and how to watch runtime log of server.
Just my two cents.
I use nodemon daily while developing and I dont think its something you want to use in place of something like forever. Nodemon is used when developing, the software will detect when there has been a file change and restart the server but for deployment it should not be considered.
There is no need to change either because forever has this use case handled with the --w or --watchDirectory comand that will watch for file changes(It can be found here on their readme).
I wasn't quite sure what to call this question but here i go:
i have a remote server where i have installed node.js now normally this would be how i start the server:
ssh root#ip
cd /var/www/mydomain/server
nodejs server.js
This works without any issues however what happens when i close down the terminal? How can i make sure that the server doesn't just stop. And how can i control it after i have started it (for instance restarting / stopping it).
There are plenty of solutions here, but maybe the most easy to start with is using forever.
Forever is a npm module that keep your app running and restarts it if it crashes.
Also there are more advanced solutions, like using PM2, which I recommend, but first take a look at forever.
I have 2 or more node app. That have to run forever if i reboot my PC that i don't want to start server it's automatic start for all node app.I used /ect/init.d node-app file and made some changes it's work but only for one node app but I have to many app on 1 server. Please any on help me.
Here is what you need to do this:
https://github.com/nodejitsu/forever
I have a SailsJS app set up on a Webfaction server. Everything works nicely (site can be accessed through browser, console works) when I run the app via any of the following commands, with and without the --prod param:
sails console,
sails lift,
node app.js
However, when I try to run the app with forever using forever app.js I get a 502 error, as if nodejs server isn't even running. When I run forever list I can see app.js listed among running processes.
How can I have my app run with forever?
Forever is considered outdated by many in the Node community, and thankfully, has been replaced by several other fantastic (dare I say, better) tools.
If you're running a newer flavor of Ubuntu, you can always install systemd and kick off the application that way. If you're seeking something more streamlined, Phusion Passenger might be your ticket. It has a long track record of successes, and I wouldn't hesitate to toss it into production.
I managed to solve this issue; the problem occurred due to SailsJS migration prompt which shows up when you start the server. Running app.js with forever worked, but the server didn't start because the script hanged waiting for a prompt reply. If you encounter this issue just make sure you have your migrate option set in model config to avoid running into migration prompt.
I've successfully just created a new droplet on Digital Ocean using their MEAN on Ubuntu 14.04 image. I can run my app from the terminal using 'grunt serve' and then view it in the browser at "ip_address:3000". But I still don't understand how I can serve it permanently, by which I mean, keep the app running even after I close my terminal. I've heard of the tool "Forever", but I don't really understand it. Do I even need it or is there another simpler way?
On the command line do:
$ export NODE_ENV=production
will setup production environmental
$ grunt build
will create necessary .min.js and min.css
$ forever start server.js
will load the server with forever, that its a package thats makes sure the node server will restart if an error and will log.
I don't know digital ocean at all, but I can tell you that you are looking for a webserver such as nginx.
The way you are running your server is really just for development purposes. That's why when you close your terminal the application stops execution.
Setting up servers can be its own large task. This is a nodejs nginx example Node.js + Nginx - What now?
You may have to Google for some more specific examples or tutorials on how to do it with digital ocean.
EDIT: you can also run a background process that will not stop executing when you exit the shell session. http://linuxtidbits.wordpress.com/2008/02/01/background-a-process/