# Setting Up Your First Node.js Application Step-by-Step

Starting with Node.js for the first time can feel confusing, but the setup is actually very simple. In this guide, you will go step by step from installing Node.js to running your first server.

* * *

## 1\. Installing Node.js

To begin, you need to install Node.js on your system.

*   Go to the official website: https://nodejs.org
    
*   Download the **LTS (Long Term Support)** version (recommended for beginners)
    
*   Run the installer and follow the default steps
    

The installation also includes npm (Node Package Manager), which is used to install libraries.

* * *

## 2\. Checking Installation Using Terminal

After installing, you should verify that Node.js is correctly installed.

Open your terminal or command prompt and run:

```javascript
node -v
```

This will show the installed Node.js version.

Next, check npm:

```javascript
npm -v
```

If both commands return versions, your setup is successful.

* * *

## 3\. Understanding Node REPL

Node.js provides a built-in environment called **REPL**.

REPL stands for:

*   Read
    
*   Evaluate
    
*   Print
    
*   Loop
    

It allows you to run JavaScript code directly in the terminal.

### Start REPL:

```bash
node
```

Now you can type JavaScript:

```js
2 + 3
```

Output:

```plaintext
5
```

You can also try:

```javascript
console.log("Hello from REPL");
```

To exit REPL:

```bash
.exit
```

REPL is useful for quick testing and learning.

* * *

## 4\. Creating Your First JavaScript File

Now let’s create your first Node.js program.

1.  Create a new folder (for example: `node-app`)
    
2.  Inside the folder, create a file named:
    

```plaintext
app.js
```

3.  Add the following code:
    

```js
console.log("Hello, Node.js!");
```

* * *

## 5\. Running Script Using Node Command

To run your file, open terminal in the same folder and execute:

```javascript
node app.js
```

Output:

```javascript
Hello, Node.js!
```

This is your first Node.js program running successfully.

* * *

## 6\. Writing a Hello World Server

Now let’s create a simple server using Node.js.

Update your `app.js` file:

```js
const http = require('http');

const server = http.createServer((req, res) => {
  res.end("Hello World from Node.js Server");
});

server.listen(3000, () => {
  console.log("Server is running on port 3000");
});
```

### What this code does:

*   Imports the built-in `http` module
    
*   Creates a server
    
*   Sends a response when a request comes
    
*   Starts listening on port 3000
    

* * *

### Run the server:

```bash
node app.js
```

Now open your browser and go to:

```plaintext
http://localhost:3000
```

You will see:

```plaintext
Hello World from Node.js Server
```

* * *

## Final Understanding

*   You installed Node.js and npm on your system
    
*   Verified the installation using terminal commands
    
*   Learned how to use the REPL environment for quick experimentation
    
*   Created your first JavaScript file and executed it using Node
    
*   Built a basic HTTP server and understood how it responds to requests
    
*   Learned how Node.js runs outside the browser and can be used to create backend applications
    

* * *

## Summary

By completing these steps, you have built a strong foundation in Node.js. You now understand how to set up the environment, run JavaScript outside the browser, and create a working server. This is the first step toward building real-world applications such as APIs, web servers, and full-stack projects. From here, you can start exploring frameworks like Express.js, working with databases, and building scalable backend systems.
