To begin, install Node.js on your development computer.
Windows: Navigate to the download page and download/run the installer.
Mac: Navigate to the download page and download/run the installer. Alternatively, you can install Node via Homebrew using brew install node
. Homebrew is a command-line package mananger for Macintosh, and more information about it can be found on the Homebrew website.
Linux: Follow the instructions for your distro on the command line installation page.
To run a Node.js program, simply run node app.js
or nodejs app.js
, where app.js
is the filename of your node app source code. You do not need to include the .js
suffix for Node to find the script you'd like to run.
Alternatively under UNIX-based operating systems, a Node program may be executed as a terminal script. To do so, it needs to begin with a shebang pointing to the Node interpreter, such as #!/usr/bin/env node
. The file also has to be set as executable, which can be done using chmod
. Now the script can be directly run from the command line.