3

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?

3
  • 8
    why not have the shell script cd into the app directory to run it? Commented Jan 28, 2016 at 4:25
  • Oh, yes! I didn't think of that @SterlingArcher. But still (now that I asked the question) is there another way, where even if I move the project into a different location, the script would still run Commented Jan 28, 2016 at 4:35
  • 1
    Could you please share the error log? Normally, it not has any issue with dependencies location. Commented Jan 28, 2016 at 4:37

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. this works, but I don't know why! is there something I could read to understand what you did there. Thanks
the .profile is the config file to be read by shell on every interactive login (i.e. when you open your terminal or when you use pseudoterminal). So in this case when u launch your terminal the variable MY_COOL_NODE_APP get exported, hence can be used by any other bash script you will run.
I suggest you read this tldp.org/LDP/abs/html to get more insight into bash scripting, and some general introduction to Linux system

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.