Basic Example of Node.js Application
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Welcome to w3wiki Node.js Tutorial');
}).listen(8080);
Output on http://localhost:8080
Welcome to w3wiki Node.js Tutorial
Explanation:
- To run this Node.js code, save it as a
server.js
file and run “node server.js"
in your terminal. - The server is set to listen on the specified port(8080) and host name(http://localhost:8080). When the server is ready, the callback function is called, in this case informing us that the server is running.
Node.js Tutorial
Node.js (Node js) is an open-source and cross-platform JavaScript runtime environment. It runs on Chrome’s V8 JavaScript engine. It allows developers to run JavaScript code on the server. Node.js enables developers to get into the server-side world.
In this Node.js Tutorial, we’ll learn all the basic to advanced concepts of Node.js such as Event loop, modules, node package manager, installation of node.js, Error handling, architecture, Async/Await etc.