I have a wordpress backend + nextjs server-side-rendering/react app set up on Ubuntu 18.04. I’m following this tutorial on correctly setting up nodejs apps: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04
My node app starts with this start script:
"start": "export NODE_ENV=production PORT=8000 && node server.js"
If I simply run npm run start, then I am able to get a response when I curl http://localhost:8000
However, if I go through PM2, and I run pm2 start npm – start, then PM2 shows the process as running but I no longer get a response when I run curl.
curl: (7) Failed to connect to localhost port 8000: Connection refused
Is this normal? how can I check the response?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Greetings!
I encourage anyone else to weigh in here, as this stack is not my specialty. That said, I wanted to see if I could offer any reasonable thoughts.
I’m wondering if the environment variables are failing to pass through when using pm2. If you hard define NODE_ENV and PORT in the app, does it change anything?
Jarland
OK the problem in my case was that I had to use pm2 start npm – run start . I was missing “run”. Otherwise it works.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.