Steps to Setup the Node App
Step 1: Initialize the Node App using the below command:
npm init -y
after the above step package.json file will be created.
Step 2: Create a new file with name of index.js or server.js
Example: Below is the basic example of the Node JS:
// Import the 'http' module
const http = require('http');
// Create an HTTP server that responds with "Hello, World!" to all requests
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Welcome to w3wiki!\n');
});
// Listen on port 3000 and IP address '127.0.0.1'
server.listen(3000, '127.0.0.1', () => {
console.log('Server running at http://127.0.0.1:3000/');
});
Steps to run the Node App:
node <filename>
Output:
What is Node?
Node is a JavaScript runtime environment that enables the execution of code on the server side. It allows developers to execute JavaScript code outside of a web browser, enabling the development of scalable and efficient network applications.
Table of Content
- What is Node?
- Steps to setup the Node App
- Advantages of Node
- Disadvantages of Node
- Learn More