What is the `PM2` for command `yarn run start`?
Asked Answered
H

4

41

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"
  },
Hesler answered 26/11, 2019 at 8:41 Comment(0)
I
74

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
Ineffective answered 26/11, 2019 at 8:48 Comment(2)
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).Moniz
is there a way to run this command with sudo access? I got permission access denied when running yarn start on port 80Hailstorm
M
71

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.

Mv answered 28/7, 2020 at 9:52 Comment(4)
Thank you. This should be the top answerLampyrid
Hi Christoph. I upvoted your answer. Can you also explain why ?Childress
Thank you! the bash interpreter flag made it fail on ubuntu 20!Shirleyshirlie
with option 'watch' , you can make an app enable with watch & reload. start with '--watch' option, or simply you can restart by pm2 restart _app-id_ --watchDumbbell
U
10

my pm2 version is 5.2.0

pm2 start "yarn start" --name yourProjec

Urbanna answered 26/6, 2022 at 11:41 Comment(1)
it works for me in version 5.2.2 tooBrickey
O
4
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.

Overcloud answered 31/5, 2022 at 4:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.