Node.js / Node.js Basics

Installing Node.js and NPM

This tutorial will guide you through the process of installing Node.js and the Node Package Manager (NPM) on your system. NPM is the default package manager for Node.js.

Tutorial 2 of 5 5 resources in this section

Section overview

5 resources

Covers the fundamental concepts of Node.js, including installation, basic commands, and JavaScript runtime.

Introduction

In this tutorial, we will cover the process of installing Node.js and the Node Package Manager (NPM) on your system. Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. NPM is the default package manager for Node.js, and it is used for installing and managing package dependencies.

By the end of this tutorial, you will be able to:

  • Install Node.js and NPM on your system
  • Understand the basic concepts of Node.js and NPM
  • Execute simple Node.js programs

Prerequisites:

  • Basic understanding of how to use the terminal or command prompt
  • Familiarity with JavaScript is helpful, but not necessary

Step-by-Step Guide

  1. Installing Node.js and NPM:

Visit the official Node.js website at https://nodejs.org/en/download/ and choose the appropriate package for your operating system. The installation process includes NPM, so you don't need to install it separately.

  1. Verification:

After the installation, open your terminal or command prompt and type the following commands to confirm the successful installation of Node.js and NPM:

bash node -v npm -v

These commands should display the installed versions of Node.js and NPM respectively.

Code Examples

  1. Create a Simple Node.js Program:

Open a new file named app.js and write the following JavaScript code:

javascript console.log('Hello, World!');

To run this Node.js program, open your terminal and type:

bash node app.js

This command will execute the app.js file with Node.js and display 'Hello, World!' on the console.

Summary

In this tutorial, we have installed Node.js and NPM on your system and verified their installation. We also ran a simple Node.js program. Next, you can start learning more about Node.js and NPM, how to create server-side applications, or how to manage and install packages using NPM.

For further learning, here are some resources:

  • Node.js Documentation: https://nodejs.org/en/docs/
  • NPM Documentation: https://docs.npmjs.com/

Practice Exercises

  1. Create a Node.js program that logs your name and the current date to the console.

  2. Install a package from NPM, import it into your Node.js program, and use the package in some way.

Solutions:

  1. Here is an example of how you might complete the first exercise:

```javascript
// Use JavaScript's built-in Date object to get the current date
var currentDate = new Date();

console.log('My name is John Doe');
console.log('The current date is', currentDate);
```

  1. For the second exercise, you might use the moment package to format the date:

First, install the moment package using NPM:

bash npm install moment

Then, use it in your Node.js program:

```javascript
// Import the 'moment' package
var moment = require('moment');

// Format the current date using 'moment'
var formattedDate = moment().format('MMMM Do YYYY, h:mm:ss a');

console.log('The formatted date is', formattedDate);
```

This program will display the current date in a more human-friendly format.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Favicon Generator

Create favicons from images.

Use tool

EXIF Data Viewer/Remover

View and remove metadata from image files.

Use tool

XML Sitemap Generator

Generate XML sitemaps for search engines.

Use tool

PDF to Word Converter

Convert PDF files to editable Word documents.

Use tool

PDF Compressor

Reduce the size of PDF files without losing quality.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help