Home > OS >  How can I use next express in production
How can I use next express in production

Time:12-11

When I run "yarn start" it runs only my next application but not my express server.

I have already tried something Like "SET NODE_ENV=production && node server/server.js" but it turns on the develop version (with js not compressed).

Is there a way to use the next build version with the express server?

CodePudding user response:

Yes, you can:

  1. Next (Frontend, PORT: 3000)
  2. Express (Backend, PORT: 5000)
  3. Install pm2 globally
  4. To run the Next build version, navigate to the project directory then:
    • pm2 start yarn --name "next" -- start
  5. To run the Express server, navigate to the server directory then:
    • pm2 start server.js --name "server"
  6. Use PM2 configuration file to manage multiple applications.

CodePudding user response:

I just had to use

"start": "export NODE_ENV=production&&node server/server.js"

The export was missing because my OS is redhat. Before I was trying without the export.

  • Related