Skip to content

Hello World Wide Web⚓︎

In this tutorial we'll create a very simple web app and verify that it displays text in a web browser.

Set Up PNPM⚓︎

Install pnpm to manage installed node versions. While pnpm is great at managing other packages used by your project, we'll keep this simple by using no external dependencies other than node itself.

curl -fsSL https://get.pnpm.io/install.sh | sh -

Install Node⚓︎

Node.js allows us to implement a server application in javascript.

pnpm env use --global 24

Add Source⚓︎

Create a new file index.js and paste the following code.

index.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
const { createServer } = require('node:http');

const hostname = '127.0.0.1';
const port = 3000;

const server = createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Code taken from An Example Node.js Application.

Run the App⚓︎

pnpx node index.js
Output
Server running at http://127.0.0.1:3000/

Viewing in Browser⚓︎

Open http://127.0.0.1:3000/ in a web browser.

Hello World in a browser window