Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run my node script using a shell script file

I am creating a personal site using node. It is going to help me keep track of the ebooks that I am reading.

At the moment, I need to cd to the project folder and run node server.js.

I thought I'd create a shell script and then I'd just have to double click on the file. The file would have the following code:

#!/usr/bin/env bash 
node server.js 

The first error I've got was that server.js is not found at the root directory, I fixed that by typing the full back, then it threw same error for all the dependencies in the application

(I have never used shell scripting)

Is what I am trying to do possible?

like image 326
relidon Avatar asked Sep 28 '26 20:09

relidon


1 Answers

I am assuming you are Linux user.

  1. Set the path in your $HOME/.profile

export MY_COOL_NODE_APP=$HOME/nodejs/app/cool_app

  1. Now your script will run as:

node $MY_COOL_NODE_APP/server.js

So in case if you move your app, you will need to update your .profile

like image 66
Yerken Avatar answered Oct 01 '26 16:10

Yerken