Node.js is an open-source, cross-platform JavaScript runtime environment that enables server-side scripting. It is used for building fast, scalable network applications. Node.js is based on the JavaScript programming language and uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
Example:
A simple Node.js application that prints “Hello World” to the console can be written as follows:
const http = require(‘http’);
const hostname = ‘127.0.0.1’;
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader(‘Content-Type’, ‘text/plain’);
res.end(‘Hello Worldn’);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});