Table of Contents
Step 1: Install Node.js and npm
- Go to the official Node.js website.
- Download and install the latest LTS (Long Term Support) version.
- Verify the installation by running the following commands in your terminal:
node -v
npm -v
These commands will display the installed versions of Node.js and npm.

Step 2: Initialize Your Node.js Project
To create a new Node.js project, use npm to initialize a project directory. This creates a package.json file, which will manage your project dependencies.
1. Create a new folder for your project
mkdir my-node-app
cd my-node-app
npm init
Step 3: Install Dependencies
Node.js projects often require external libraries or modules, which can be easily installed using npm. For example, if you’re building a web server, you can install Express.js, a popular web framework.
1. To install Express, run
npm install express
Step 4: Create Your First Server
touch app.js
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
Step 5: Run Your Node.js Project
node app.js
Step 6: Manage Your Dependencies and Scripts
As your project grows, you will need to manage your dependencies and automate tasks. Here are some tips for managing your Node.js project:
- Install Additional Dependencies: You can add more libraries using
npm install <package-name>
. - Add Scripts: In your
package.json
, you can define scripts such as:
"scripts": {
"start": "node app.js"
}
Step 7: Use Version Control with Git
To maintain your project effectively, it’s crucial to integrate version control. Follow these steps to set up Git:
1. Initialize Git
git init
node_modules/