I have a node app locally and I normally run it using the run button in the web storm, which works fine. While I am documenting the project I came across this blocker: if I try running the same app through the terminal using the command: node app.js , the server starts but the browser throws and error stating "This site can’t be reached" "localhost refused to connect".
Because the port is occupied.
You can change it using app.listen({port})...
or
linux:
export PORT=4500
node server.js
windows:
set PORT=4500
node server.js
I found this myself.. since I used the scaffolding app and it stores info related to server at bin/www, so we will not be able to run the app using the command : node app.js but instead we could run the app using nodemon(which I installed globally on my machine)
Love nodemon for this awesome feature <3 :)
Related
I'm doing web automation by using Puppeteer with NodeJS. It works fine when I'm logged in to the terminal. I'm using ec2 instance Ubuntu 22 server.
But when I'm exit out of the terminal and then try to perform the task it just loads and loads and do nothing. But when I log in to check the pm2 logs then it starts working again with the terminal open.
When I check pm2 logs I get this error every time.
Error in pm2 logs:
I suppose there is problem with the command you are trying to run the app. Use the following command to run the app via pm2.
npx pm2 start app
For Cpanel Users having this issue
Login to your WHM account, click on the terminal, cd into the directory where your node js application is, then pm2 start .This was how i solved my issue.
I have developed a simple node.js application and I am trying to publish it on AWS Lightsail. I followed the instructions on this page: https://medium.com/#sharmasha2nk/aws-lightsail-bitnami-nodejs-letsencrypt-cf653573b8a1
I am connecting to Bitnami using the SHH console provided. After I start the app with node index.js command the app is up and running until I close the SHH console. As soon as I close it the application stops and “Service Unavailable” error is being displayed. How can I keep my app running on AWS even if my PC is shot down and the SHH console is closed?
I have tried restarting the apache server and AWS Lightsail instance. Neither of them helped.
httpd-app.conf file content:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
httpd-prefix.conf file content:
Include "/opt/bitnami/apps/emsnotes/conf/httpd-app.conf"
Thanks.
I would recommend you pm2
Here's how to do it quickly:
install pm2 globally using sudo npm i -g pm2
navigate to the location of your index.js via ssh
run pm2 start index.js
This will keep node running even when you disconnect the ssh session or shutdown your development computer. The process will keep running on your server in the background. This is used for running node apps in production on a server.
You can read all about it here in its documentation.
I hope I could help you, please let me know if you have any question.
Karim
I had a look at the article and frankly i see nowhere that he talk about keeping the server up and running.
Basically he is using the Bitnami Node.js stack and if you look at the docs you will see that Bitnami use Forever.js to keep the apps running on their instance, Forever is a CLI tool to monitor and keep a Node instance running in the background.
Check the docs here : https://docs.bitnami.com/general/infrastructure/nodejs/administration/start-express-server/
Here is the Git for Forever, so can read more on it: https://github.com/foreverjs/forever
I installed node-inspector.
I run it: node-debug app.js
But it opens the empty browser.
If I try to run node.js in debug mode before: node --debug app.js
It kind opens my scripts in browser.
But it's still not clear how to make it work. What to do next? Which url to use to see the working app itself in browser and trigger app to go to breakpoints?
My express app is usually running under localhost:3000. Should I run this url? It's not working.
Thanks
Okay,
I was able to figure it out. The problem was my app is Express based and it's a little bit different. For some reason it's not easy to find these differences until you start digging into every details. There is the instructions how to run debugger if you app is working under Express.
Prerequisites:
Windows 7
node.js app based on Express
Now:
Step 1. Run app in the debug mode (staying in the folder where your app.js located in the first command prompt), do either of 2: node --debug app.js or node --debug bin/www.
Step 2. Open the second command prompt and run node-inspector bin/www (or node-inspector app.js)
If you see the error that it can't access port 8080 it means that something is already listening to it. So you need to run this command differently: node-inspector --web-port=8099 bin/www
After step 1 you will able to run your app as usually in browser: localhost:3000.
After step 2 you open another browser window and enter: http://127.0.0.1:8099/?port=5858
Refer to https://github.com/openfin/process-manager
Based on the README.md, I have done the following steps:
npm install
node server
I am able to see the following message from terminal(windows 7)
$ node server
Express server listening on port 5040
How do I launch the application?
I have tried to point to the localhost:5040 through chrome browser and ONLY see three tabs 'Processes', 'Cache', 'Logs' without any information.
How can I fix the issues?
npm i -g openfin-cli
openfin -l -c http://localhost:5040/app_local.json
The server script is running a local express server that hosts an OpenFin enriched web app so all you need to do it launch it on OpenFin, which in the case above we are doing with the CLI.
You can also use a node module to launch i.e. here
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.