Start a server with Node.js

To start a server with Node.js, we will need the http module. The http module is a core module which means that it comes with Node, so we won’t need any other dependencies. Here is the code that will accomplish this: const http = require(‘http’); const hostname = “127.0.0.1”; const port = 3000; const server = http.createServer((request, response) => { response.statusCode = 200; response.setHeader("Content-Type", "text/plain"); response.end("Hello World! I am a server....

June 17, 2021 · 1 min