DEV Community

Priyadarshini Sharma
Priyadarshini Sharma

Posted on

Working with the Node.js Tools

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
(Reference - Mastering Node.js Web Development by Adam Freeman)

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

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

Image description

Image description

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

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

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

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
The node command starts the Node.js runtime and executes the specified JavaScript file, producing the following output:

Image description

Understanding the npm tool

Image description

Reference Material - Mastering Node.js Web Development by Adam Freeman)

Top comments (0)