# Node.js Kickstart: Install, Explore the REPL, and Launch Your First Server

JavaScript was originally designed to run inside browsers. But with Node.js, developers can run JavaScript outside the browser — directly on their computers and servers.

In this article, you’ll learn how to:

*   Install Node.js
    
*   Verify the installation
    
*   Understand the Node REPL
    
*   Create and run your first JavaScript file
    
*   Build a simple “Hello World” server
    

* * *

# What Is Node.js?

Node.js is a JavaScript runtime built on Google Chrome’s V8 engine. It allows JavaScript to run on the server side.

Before Node.js:

*   JavaScript mostly handled browser interactions
    
*   Backend development used languages like PHP, Java, or Python
    

After Node.js:

*   JavaScript could handle both frontend and backend development
    

* * *

# Installing Node.js

The easiest way to install Node.js is through the official website:

[Node.js Official Website](https://nodejs.org?utm_source=chatgpt.com)

## Steps

1.  Open the website
    
2.  Download the **LTS (Long Term Support)** version
    
3.  Run the installer
    
4.  Follow the default installation steps
    

The installer automatically includes:

*   Node.js runtime
    
*   npm (Node Package Manager)
    

* * *

# Checking the Installation

After installation, open your terminal or command prompt.

Run:

```bash
node -v
```

Example output:

```bash
v22.3.0
```

Now check npm:

```bash
npm -v
```

Example:

```bash
10.8.1
```

If both commands return versions, Node.js is installed correctly.

* * *

# Understanding the Node REPL

Before writing files, Node.js provides an interactive environment called the **REPL**.

REPL stands for:

*   **R**ead
    
*   **E**valuate
    
*   **P**rint
    
*   **L**oop
    

It works like a live JavaScript playground inside the terminal.

## Starting the REPL

Run:

```bash
node
```

You’ll see something like:

```bash
>
```

Now you can execute JavaScript directly.

Example:

```js
> 2 + 3
5
```

```js
> const name = "Vaibhav"
undefined
```

```js
> name
'Vaibhav'
```

To exit:

```bash
.exit
```

or press:

```bash
Ctrl + C
```

twice.

* * *

# Creating Your First JavaScript File

Create a file named:

```bash
app.js
```

Add this code:

```js
console.log("Hello from Node.js");
```

* * *

# Running the Script

Open terminal in the same folder and run:

```bash
node app.js
```

Output:

```bash
Hello from Node.js
```

This is your first Node.js program.

* * *

# How Node Executes a Script

## Flow Overview

```text
JavaScript File
       ↓
Node.js Runtime
       ↓
V8 Engine Executes Code
       ↓
Output Appears in Terminal
```

* * *

# Writing a Hello World Server

Now let’s create a very basic web server using Node.js.

Update `app.js`:

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

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

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

* * *

# Running the Server

Run:

```bash
node app.js
```

Terminal output:

```bash
Server running on port 3000
```

Now open your browser and visit:

```text
http://localhost:3000
```

You’ll see:

```text
Hello World
```

* * *

# Understanding What Happened

Let’s break the code down:

## Importing the HTTP Module

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

Node.js includes built-in modules. The `http` module helps create web servers.

* * *

## Creating the Server

```js
http.createServer((req, res) => {})
```

This creates a server.

Parameters:

*   `req` → incoming request
    
*   `res` → response sent back to client
    

* * *

## Sending Response

```js
res.end("Hello World");
```

This sends text back to the browser.

* * *

## Listening on a Port

```js
server.listen(3000)
```

The server waits for requests on port 3000.

* * *

# Node Server Request Flow

```text
Browser Request
       ↓
Node.js Server
       ↓
Request Handler Executes
       ↓
Response Sent Back
```

* * *

# Why This Matters

With just a few lines of code, Node.js can:

*   Handle HTTP requests
    
*   Serve APIs
    
*   Build backend applications
    
*   Power real-time systems
    

This small example is the foundation of larger backend applications.

* * *

# Common Beginner Mistakes

## 1\. Running command outside project folder

Make sure terminal is inside the same directory as `app.js`.

* * *

## 2\. Forgetting to save the file

Always save before running:

```bash
node app.js
```

* * *

## 3\. Port already in use

If port 3000 is busy, use another:

```js
server.listen(5000)
```

* * *

# Final Thoughts

In this article, you learned:

*   How to install Node.js
    
*   How to verify installation
    
*   What the REPL is
    
*   How to execute JavaScript files
    
*   How to create a simple server
    

These basics are important before moving into:

*   modules
    
*   npm packages
    
*   async programming
    
*   APIs
    
*   frameworks like Express
    

Once you understand how Node.js runs JavaScript, backend development becomes much easier to learn.
