# Setting Up Your First Node.js Application 

**Node.js** is an **open-source, cross-platform JavaScript runtime environment** that allows developers to execute JavaScript code outside of a web browser, primarily for building server-side and network applications. Built on Google’s **V8 JavaScript engine**, it enables the use of a single programming language for both frontend and backend development, streamlining workflows and reducing context switching.

### Installing Node.js

To setup our first node.js application, we need to download the node.js from the official docs of node.js.

You can visit to this download link [https://nodejs.org/en/download](https://nodejs.org/en/download)

### Checking installation using terminal

Once node.js is installed on the local system , try running these commands.

```javascript
node -v // show the nodejs version, eg. - v22.13.1
npm -v // show the npm version, eg. - 11.5.2

// npm is the package manager for the node.js. 
```

### Understanding Node REPL

Before writing files, let’s understand something powerful:

`REPL(Read Eval Print Loop)`

Just open the terminal and run `node` command. With this environment we can run the JS directly in the terminal.

![](https://cdn.hashnode.com/uploads/covers/63cbeb71587fc59d3cd75412/23d80f35-8da3-4400-a88f-d56b44f6ab31.png align="center")

For Example -

![](https://cdn.hashnode.com/uploads/covers/63cbeb71587fc59d3cd75412/f680b602-df51-4d58-8203-50e6ff90f3db.png align="center")

### Creating first JS file

Create the file with any name and with .`js` extension.

To create the file directly from the terminal, you can use `touch` utility.

```shell
touch app.js 
```

This `touch` utility will only works with unix based system. This utility does not works in the windows.

Add this code in the file :

```javascript
console.log("Hello World");
```

### Running script using node command

To run the created file we can use this command

```javascript
node <file_name>.js
```

replace the `<file_name>` with your actual file name.

### Writing Hello World server

Now just replace the code inside `app.js` with this -

```javascript
// app.js
import { createServer } from 'node:http';

const server = createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World!\n');
});

// starts a simple http server locally on port 3000
server.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});
```

Now run `node app.js` command.

![](https://cdn.hashnode.com/uploads/covers/63cbeb71587fc59d3cd75412/36a63771-72c5-468a-a1d0-6478db113846.png align="center")

![](https://cdn.hashnode.com/uploads/covers/63cbeb71587fc59d3cd75412/a5b4c502-5c46-433f-a35a-e633f53f4a27.png align="center")

You just created your first backend server. That all for this article, if you like these articles do follow me on X and github.
