![]() |
NodeJS provides a straightforward way to create HTTP servers, allowing developers to build web applications and APIs without relying on external web servers like Apache or Nginx. Let’s explore how to create a simple HTTP server in NodeJS. Steps to Create a NodeJS Server:Step 1: Initialize the NPM using the below command. Using this the package.json file will be created. npm init -y
Step 2: Import the HTTP Module: const http = require('http');
Step 3: Create a Server using the const server = http.createServer((request, response) => { Step 4: Handle Requests: const server = http.createServer((request, response) => { Example: After implementing the above steps, we will effectively establish the NodeJS server: Javascript
Output: Hello, GeeksforGeeks!
|
Reffered: https://www.geeksforgeeks.org
Node.js |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |