[Roadmap_Node] 2_Setting Up Node

Introduction

In our last post we learn what is Node JS in very simple terms, now its time to setup our computers to be able to do some simple tasks.

Installing Node.js and NPM

There are two main approaches to installing Node.js and npm (Node Package Manager):

1. Using a Node.js Installer:

2. Using a Node Version Manager (NVM):

Verifying Installation:

Additional Notes:

I hope this comprehensive explanation helps you install Node.js and npm successfully!

Using Node JS

Here are a few simple examples to get you started with Node.js now that you have it installed:

1. Running a Basic JavaScript Program:

This will print “Hello, World!” to your terminal.

2. Using Built-in Modules:

3. Using Packages from npm:

These are just a few basic examples to demonstrate the capabilities of Node.js. As you explore further, you’ll discover a vast ecosystem of packages and frameworks that empower you to build complex and scalable applications.

Package.json Configuration

In Node.js, package.json is a fundamental file that acts as a manifest for your project. It stores essential information about your application, including:

1. Project Metadata:

2. Dependencies:

3. Scripts:

4. Other Optional Fields:

Creating a package.json File:

There are several ways to create a package.json file:

Example package.json:

{
  "name": "my-awesome-app",
  "version": "1.0.0",
  "description": "A simple Node.js application",
  "keywords": ["node", "javascript"],
  "license": "MIT",
  "author": "John Doe",
  "main": "index.js",
  "scripts": {
    "start": "node server.js",
    "test": "jest"
  },
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "jest": "^28.0.1"
  }
}

In summary, package.json is a vital configuration file in Node.js projects. It centralizes information about your application, dependencies, and scripts, making development and collaboration more efficient.

What is Node Version Manager (NVM)

Node Version Manager (NVM) is a tool that allows you to manage multiple versions of Node.js on a single system. This can be extremely beneficial for developers for several reasons:

1. Working on Projects with Different Node.js Requirements:

2. Testing Code Compatibility Across Versions:

3. Trying Out New Node.js Features:

How NVM Works:

Benefits of Using NVM:

Installation:

NVM installation instructions vary depending on your operating system. Here are some resources to get you started:

Using NVM Commands:

Once installed, you can use commands like:

By leveraging NVM, you can effectively manage multiple Node.js versions on your machine, streamlining development workflows and ensuring compatibility across various projects.

Conclusion

We learned how to setup NODE JS, performed some basic scripts, learned about what is Package.json and how to configure it, finally what is an NVM to control our Node version, very basic concepts so far, but a right step for now.

See you on the next post.

Sincerely,

Eng. Adrian Beria