// Import 'http' module
const http = require('http');
// Create a simple HTTP server
const server = http.createServer((req, res) => {
res.end('Hello, Node.js!');
});
// Start the server and listen on port 3000
server.listen(3000, () => {
console.log('Server is listening on port 3000');
});
code
Simple HTTP Server in Node.js
This Node.js code creates a basic HTTP server using the 'http' module. The server responds with 'Hello, Node.js!' for all incoming requests. The server is started and listens on port 3000. The comments provide explanations for each part of the code.
Node.js
HTTP Server
createServer
server.listen