I'm trying to create an executable in the Ubuntu console, but I can't. The truth is that I have only tried with the following command, no matter how much I search in Google, I can't find anything. I searched the possible questions on Stack, but none convinced me.
This is what I add to the top of my file, without success:
#!/bin/node
What should I add to a JavaScript file to create an executable in Node.js?
Replace the line you put with this one ( source ):
That line of code (which should go at the beginning of the file) tells the system to use Node to run the script.
So for example, if you have the following saved in a file called helloworld.js:
and run it from the command line doing
./holamundo.js
(important: the file must have execute permissions which you can add withchmod
, otherwise you will get an error), then the result will be: