Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and it’s not a programming language. Most people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like APIs like Web App or Mobile App. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on.
Example: In this article, we will learn how to write "Beautiful Life" in Node.js. Create a .js file like we have created the geeksforgeeks.js file and write down the following code in it.
Filename: geeksforgeeks.js
const http = require('http');
// Create a server object:
http.createServer(function (request, response) {
// Write a response to the client
response.write('Beautiful Life');
// End the response
response.end();
// The server object listens on port 8080
}).listen(8080);
Step to run file: Open CMD and go to the folder directory where the above file is kept, then run the following command.
node geeksforgeeks.js
Output: Open any browser and go to http://localhost:8080/, you will see the following output.