Run javascript file with GitBash from shortcut

Viewed 453

So usually to start my js files I right click and "Git Bash Here" then I node index.js.

Now I'm wondering if that can be done through a shortcut instead.

I've looked around everywhere and no methods worked for me but I have managed "C:\Program Files\Git\git-bash.exe" -c and it stays open.
Any help is appreciated.

2 Answers

The alternative to bash -c would be, on Windows 10:

 wsl.exe --exec node /mnt/c/MyFiles/index.js

That could also be setup as a shortcut.

Update: There's no need to build Node.js

Since you already have Node.js installed, you can use the existing exe.

You can use node.exe instead of Git Bash for creating a shortcut.

Here are the steps I used (windows 10):

  • Go to C:/Program Files/nodejs.
  • Click Create shortcut for node.exe.
  • Right click on the shortcut and open Properties
  • Add the CLI args to the Target section. Before it was "C:\Program Files\nodejs\node.exe", but I changed it to "C:\Program Files\nodejs\node.exe" index.js. Also change the Start In to be the working directory you want.
Related