The first thing we want to do when getting ready to code in node.js is make sure that Node
and NPM
are installed on our machine. Start by opening a command window and type the command node -v
.
Then check to confirm that NPM is installed also using the command npm -v
:
Once that is confirmed, create a new node.js file called hello.js and add this single line of JavaScript code to test whether the script is running:
console.log("Hello world.")
Now once that file is saved, try running it from the command line with the command node hello.js
. Note: Don’t forget to cd to the folder that the file was saved in.
If you see the words “Hello world.” on the next line, it confirms that you have successfully created and run a node.js script.