Skip to main content

Command Palette

Search for a command to run...

How do you create a simple server in Node.js that returns Hello World?

Updated
1 min read
How do you create a simple server in Node.js that
returns Hello World?
const http = require('http');
const port = 3000;

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

server.listen(port, () => console.log(`Server
is now running on http://localhost:${port}/`));
});

More from this blog

R

Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer

157 posts

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, ExpressJS, MySQL, MongoDB. Love collaborating & making a difference