Node JS Install & Project Setup

In this section, you will learn how to install Node.js on Windows, macOS, and Linux, and how to set up a simple TypeScript-based Express project.

๐Ÿš€ Step 1: Node JS Install (Windows / macOS / Linux)

Before setting up a Node.js project, you need to install Node.js and npm (Node Package Manager).

โœ… For Windows (Recommended)

  1. Go to the official Node.js website: https://nodejs.org

  2. Download the LTS (Long-Term Support) version for Windows.

  3. Run the installer:

    • Accept the license

    • Click “Next” on all default steps

    • Enable “Automatically install necessary tools” (optional, for advanced usage)

  4. Once installed, open Command Prompt and verify installation:

sh
node -v
npm -v

If these commands return versions (e.g., v20.11.1), Node.js is installed correctly.

๐Ÿ–ฅ๏ธ For macOS

Install Homebrew (if not already installed):

sh
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

Then install Node.js:

sh
brew install node

Verify the installation:

sh
node -v
npm -v

๐Ÿง For Linux (Ubuntu/Debian)

sh
sudo apt update
sudo apt install nodejs npm -y

Or use NodeSource for latest versions:

sh
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash –
sudo apt install -y nodejs

Verify installation:

sh
node -v
npm -v

๐Ÿ› ๏ธ Step 2: Create Project Directory

โš ๏ธ All the following commands assume you’re using Command Prompt (Windows) or Terminal (macOS/Linux).

sh
mkdir nodejs-project
cd nodejs-project

๐Ÿ“ฆ Step 3: Initialize package.json

Create a package.json file using:

sh
nodejs-project > npm init

Follow the prompts or press Enter to accept defaults. It will generate a file like this:

sh
{
“name”: “nodejs-project”,
“version”: “1.0.0”,
“main”: “index.js”,
“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1″
},
“license”: “ISC”
}

๐Ÿ“Œ What is the "scripts" section?

sh
“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1″
}

The scripts section lets you define shortcut commands. For example, npm test will run the command shown above.

๐Ÿงพ Step 4: Update package.json Scripts

Open package.json and replace the scripts and main fields like this:

sh
“main”: “src/index.ts”,
“scripts”: {
“start”: “nodemon –exec ts-node src/index.ts”
}

๐Ÿ“Œ Explanation:

  • start: Runs your app using nodemon, which monitors for file changes.

  • ts-node: Executes TypeScript files directly without compiling to JS.

๐Ÿ“ฅ Step 5: Install Dependencies

Run this command to install all the required packages:

sh
nodejs-project > npm install express
nodejs-project >ย  npm install –save-dev typescript ts-node nodemon @types/node @types/express

๐Ÿ“š Package Breakdown

Package Description
express Web framework for handling routes and requests
typescript Adds type safety to JavaScript
ts-node Executes TypeScript files directly without compilation
nodemon Automatically restarts server on file changes
@types/node Type definitions for Node.js runtime
@types/express Type definitions for Express.js

๐Ÿ“ Step 6: Create Project Structure

Create a src folder and an entry file:

sh
nodejs-project > mkdir src
nodejs-project > echo. > src\index.ts

Create a index.ts file

โœ๏ธ Step 7: Add Express Server Code

Open src/index.ts and paste the following code:

sh
import * as express from ‘express’;
const app: express.Application = express();
app.listen(5000, () => {
console.log(‘Server is running at port 5000’);
});

Step 8: Add TypeScript Configuration

Download the tsconfig.json file and place it in the root of your project directory.
Download tsconfig.json

๐Ÿ“ Final Project Structure

sh
nodejs-project/
โ”‚
โ”œโ”€โ”€ node_modules/ # Installed dependencies
โ”‚
โ”œโ”€โ”€ src/ # Source code
โ”‚ โ””โ”€โ”€ index.ts # Entry point of the application
โ”‚
โ”œโ”€โ”€ package.json # Project metadata and dependencies
โ”œโ”€โ”€ package-lock.json # Dependency lockfile
โ”œโ”€โ”€ tsconfig.json # TypeScript configuration

โ–ถ๏ธ Step 9: Start the Server

Start your server using:

sh
nodejs-project > npm start

You should see:

sh
Server is running at port 5000

Any changes you make will automatically restart the server โ€” thanks to nodemon.


โœ… Summary

In this lesson, you learned:

  • How to install Node.js on Windows, macOS, and Linux (๐ŸŸข Node JS Install)

  • How to set up a Node.js + TypeScript project

  • How to run and auto-restart a server using nodemon and ts-node

Scroll to Top