Michael J. Calkins
Michael J. Calkins

Reputation: 32635

Run node script like a bin program in command line

Can you run a node.js script:

node app.js --watch ../worker/storage/work

like this?

app --watch ../worker/storage/work

Upvotes: 4

Views: 1181

Answers (2)

Daiwei
Daiwei

Reputation: 43526

  1. Add #!/path/to/your/node at the first line of your js file.

  2. Then run:

    chmod +x yourFileName
    

    to add execute permission to your script.

  3. At last run your file like this:

    ./app.js
    

Upvotes: 2

verybadalloc
verybadalloc

Reputation: 5798

One way this could work is by creating an alias in your shell. Edit your ~/.bashrc file and add the following line:

alias app="node app.js"

More details on how to create a permanent alias: https://askubuntu.com/questions/1414/how-to-create-a-permanent-alias

Upvotes: 2

Related Questions