question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

running pm2 with npm script "react-scripts start"

See original GitHub issue

Hi,

I am trying to use pm2 on a dev server with your npm start up script react-scripts start

Do you have any recommendations on where we could execute pm2 process on node.js running this script? normally we use pm2 start server.js --watch

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

20reactions
m8r1xcommented, Nov 7, 2017

@sam3k 's command failed for me but I got it to run with a slight adjustment pm2 start node_modules/react-scripts/scripts/start.js --name “myapp”

16reactions
vladinator1000commented, Feb 22, 2018

It makes no sense to run npm start with pm2. The start script is only meant for development (because it starts a bloated development server). You need to build, then serve the app using a server meant for production, like Node with Express. Here’s what you can do:

  1. .env file in your root directory:
PORT=3002
ABSOLUTE_STATIC_PATH=C:/path/to/project/build/static/
  1. server.js in your root directory:
require('dotenv').config();
const express = require('express');
const compression = require('compression');
const path = require('path');

const app = express();

app.use(compression());

app.use('/static', express.static(process.env.ABSOLUTE_STATIC_PATH));

app.get('/', (req, res) => {
  res.sendFile(path.join(process.env.ABSOLUTE_STATIC_PATH, '../index.html'));
});

const PORT = process.env.PORT || 3002;

app.listen(PORT, '0.0.0.0', (err) => {
  if (err) { console.log(err); }
  console.info(`==> 🌎 app listening on http://localhost:${PORT}.`);
});
  1. Production script in package.json:
{
  "scripts": {
     "prod": "pm2 start ./server.js --name appName",
    }
}
  1. Start your app in production: yarn prod
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can pm2 run an 'npm start' script - node.js - Stack Overflow
Suppose we want to run the script named as 'shivkumarscript' with pm2 utility. So, our pm2 config file should be like below, containing...
Read more >
How to Build React for Production Using PM2
Follow the below steps: · 1. Create a React app (ignore 1st command if you have a project already created) · 2. Open...
Read more >
How to Run a Npm Start Script With PM2 - Coder Rocket Fuel
The commands you can use to run npm scripts with the Pm2 process manager. Examples of running the commands with the --name and...
Read more >
npm ERR! Missing script: "start" [Solved] | bobbyhadz
If you have a start command in the scripts object in your package.json file, make sure you are opening your IDE and shell...
Read more >
How to Build a Progressive Web App (PWA) with React
Running Your Application ... In your command prompt, entering 'npm start' can spin up your application to a specific localhost url. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found