There are many different downloadable versions for NodsJS across most operating systems. Often, visiting the homepage will prompt with the version detected from the browser and provide the correct build.
Installing NodeJS will require administrative access to install. Once started, selecting the default options (“/usr/local/bin” for Mac and “C:\Program Files\” for Windows) when prompted is sufficient. Total installation time is usually within a couple minutes.
Once installed, it is ready for use.
Testing if NodeJS is installed and configured correctly is a quick process. Opening a Terminal window (Mac) or Command Prompt (Windows) and running “node -v” should provide a response of the current version.
Installing NodeJS also installed an additional tool called the Node Package Manager (NPM). It has a website for more easily finding projects, but can also be found through running “npm” on the command-line of in a Terminal window.
Create or use an empty folder or directory in the current user’s folder or directiry. Name this folder “nodeTesting.”
Open a Command Prompt in Widows or Terminal window on Mac.
Note: Opening the Command Prompt in Windows will default to the current user’s home folder. On Mac, opening a Terminal window will default to the user’s home directory.
Navigate to the new folder or directory. On most operating systems this will be through using the cd command and the name of the directory.
Note: NPM will produce warnings because there is not an existing “package.json” file. This can be ignored for this test.
Using either a built-in plain text editor or one like Atom, create a new file in the same folder or directory. Name this file “testing.js”
Copy the following code into the file.
In the Command Prompt or Terminal window, run “node testing.js”.
Successfully running the code will produce either “There was a deer in the forest”, “There was a rabbit in the forest”, or “There was a fox in the forest.”
NodeJS and NPM are now ready for use in other projects!
- For each new NodeJS project, create a new folder or directory. This should always be the first step and helps organize node packages better, as they will be downloaded and sometimes even compiled in the local directory by default.
- While “nodeTesting” and “testing.js” work fine for examples, naming files in useful ways can better help organize projects. Many projects use the naming scheme of “index.js” for the central or main file to be run. This is a good practice.
- Consider using an editor like Atom or Brackets to show not only the current files, but those in the same folder or directory as well.
- Search packages on the NPM website instead of using the tool itself. While npm can be used to search, the website provides a better pictures of how many other users have downloaded the same files and if the package has been updated recently or not.