Working with the Node.js Tools
Tags: webdev, node, javascript, programming
Published: 2024-06-26 08:46:43

Here's the simple process of getting started with Node.js, beginning with the simple steps that are required to prepare for development. It explains how to execute JavaScript code using Node.js and then I introduce the real power in Node.js development: **the Node Package Manager (npm).** npm is the tool that does most of the work during development, taking responsibility for everything from downloading and installing JavaScript packages, reporting on security vulnerabilities, and running development commands.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5myqtw262opct3gxlv7.png)
(Reference - [Mastering Node.js Web Development by Adam Freeman](https://bit.ly/3KZs97f))

**Getting ready**
The key step to prepare for Node.js development is, as you would expect, to install Node.js and its supporting tools. The version of Node.js used  is 20.9.0, which is the **Long Term Support (LTS)** version.A complete set of installers for Node.js version 20.10.0 is available at https://nodejs.org/download/release/v20.10.0. Download and run the installer for your platform and ensure the **npm package manager** and the **Add to PATH** options are checked, as shown below 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4uirlu1ugfxmrk4rtqnd.png)

When the installation is complete, open a new command prompt and run the command shown below -

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/haaqqzra06x92oqp994i.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m4pjrudfmec4s63e7v28.png)

**Installing Git**
Some packages depend on Git, which is a popular version control system. Download the installer for your platform from https://git-scm.com/downloads and follow the installation instructions.Once you have completed the installation, use a command prompt to run the command shown below to check that Git is working. You may have to manually configure the executable paths:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahbxr3f2hmyjv29qw3ic.png)

**Selecting a code editor**
An editor is required to write the code that will be executed by Node.js, and any editor that supports JavaScript and TypeScript can be used. If you don’t already have a preferred editor, then Visual Studio Code (https://code.visualstudio.com) has become the most popular editor because it is good (and free)

If you are using Visual Studio Code, run the command code to start the editor or use the program icon created during installation, and you will see the welcome screen (You may need to add Visual Studio Code to your command prompt path before using the command code.)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61jy5moj61r4ylajhs2f.png)

**Using Node.js**
The entire purpose of Node.js is to execute JavaScript code. Open a command prompt, navigate to a convenient location, and create a folder named tools. Add a file named hello.js to the toolsfolder, with the content shown below -

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vpmhms1uj7y05gbjj978.png)

The Node.js API has some features that are also provided by modern JavaScript browsers, including the console.log method, which writes a message to the console. Run the command shown below in the tools folder to execute the JavaScript code:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxq52pil20r6fd5o32xc.png)
The node command starts the Node.js runtime and executes the specified JavaScript file, producing the following output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcsdk68nbmu3drcy3nql.png)

**Understanding the npm tool**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rcvob5gugd568sm8iku.png)

**_Reference Material_** - [Mastering Node.js Web Development by Adam Freeman](https://bit.ly/3KZs97f))