Home > Enterprise >  Start node.js with bash script?
Start node.js with bash script?

Time:06-05

What to do when I have to start a node.js application with a script on the raspberry pi?

Normally I go to the command line move to the map with "cd projectMap" and do this command "npm projectName"

I thought this would work but it does not.

#!/bin/bash
cd projectMap
npm projectName

CodePudding user response:

to run a nodejs script you generally run

node index.js

Replace index.js with the name of the file you want to run.

To run it with npm you have to add it as a script in the package.json like so

"scripts": {
  "start": "node index.js"
}

And to run it:

npm start

CodePudding user response:

Create a file:

sudo touch script.sh

Give permission:

sudo chmod 400 script.sh

Inside your script.sh

#!/bin/bash
cd project
npm -i
node -v // not necessary just to check the node version .
node file.js

run script.sh

./script.sh

  • Related