Using port 80 with Node.js on Windows

This article can be read in about 2 minutes.
PR

The purpose 

The following article launched an HTTP server using Node.js.

I read that using Node.js on a Unix-like OS prevents it from starting on port 80.

However, the article didn’t specify whether port 80 is usable on Windows. Intrigued, I decided to try it myself.

PR

Environment

Node.js v20.16.0

PR

tried code

I used the following code.

I only changed the port in the article above.

import http from 'node:http';

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({
    data: 'Hello World!',
  }));
});

server.listen(80);////use Poet 80
PR

Result

We are able to access it from Chrome on 127.0.0.1 (without specifying a port) This is just a record, as there’s no special know-how involved.

comment

Copied title and URL