35

I run the nodejs app with yarn run start , what is the command for pm2 I should use?

pm2 yarn run start give me an error.

My package.json content

"scripts": {
    "start": "budo main.js:dist/bundle.js --live --host 0.0.0.0",
    "watch": "watchify main.js -v --debug -o dist/bundle.js",
    "prep": "yarn && mkdirp dist",
    "build": "browserify main.js -o dist/bundle.js",
    "lint": "eslint main.js --fix",
    "deploy": "yarn build && uglifyjs dist/bundle.js -c -m -o dist/bundle.min.js"
  },
Tin
  • 424
  • 5
  • 13
tree em
  • 20,379
  • 30
  • 92
  • 130

4 Answers4

68

The error you're getting is because a bash script (yarn) is being executed with node...

Because pm2's default interpreter is set to node.

To run yarn you'll have to set the interpreter to bash:

shell:

Try the command below:

pm2 start yarn --interpreter bash --name api -- start
developerKumar
  • 1,706
  • 10
  • 14
  • Helped me a lot. Let me mention also that if your script name is something else than `start`, then you only have to replace the final `start` by your new script name. (i.e: `pm2 start yarn --interpreter bash --name api -- start:prod` if I use `yarn run start:prod`). – Ryo Shiina Nov 12 '20 at 15:44
  • is there a way to run this command with sudo access? I got permission access denied when running yarn start on port 80 – Darryl RN Jul 06 '22 at 02:03
62

For me (on ubuntu 20)

pm2 start yarn --name api -- start

would do the trick. With the bash interpreter flag it would error in pm2.

9

my pm2 version is 5.2.0

pm2 start "yarn start" --name yourProjec

小歌迷
  • 101
  • 1
  • 2
2
pm2 start yarn --name api -- start

Won't work for me.

It displays below

0|api      | /usr/share/yarn/bin/yarn:2
0|api      | argv0=$(echo "$0" | sed -e 's,\\,/,g')
0|api      | SyntaxError: missing ) after argument list

It means launching a yarn binary file with a node.js

How about this command.

pm2 start "yarn start" --name api

It work's like charm for me.

yusung lee
  • 236
  • 1
  • 12