// We can use express as shown as belowconst express =require('express')const app =express()const port =3000
app.get('/',(req, res)=>{
res.send('Hello World!')})
app.listen(port,()=>{console.log(`Example app listening at http://localhost:${port}`)})
asyncfunctionsendMe(){let r =awaitfetch('/test',{method:'POST',body:JSON.stringify({a:"aaaaa"}),headers:{'Content-type':'application/json; charset=UTF-8'}})let res =await r.json();console.log(res["a"]);}
// Load HTTP moduleconst http =require("http");const hostname ="127.0.0.1";const port =8000;// Create HTTP server const server = http.createServer((req, res)=>{// Set the response HTTP header with HTTP status and Content type
res.writeHead(200,{'Content-Type':'text/plain'});// Send the response body "Hello World"
res.end('HelloWorld
');});// Prints a log once the server starts listening
server.listen(port, hostname,()=>{console.log(`Server running at http://${hostname}:${port}/`);})
If you are looking for simplier NodeJS express is on the go choice for you.expressJS is:>NodeJS framework
>Free to use
USES=['twitter','paypal','yandex','bbc','sohu','and so on.']
Express.js, or simply Express, is a web application framework forNode.js,
released as free and open-source software under the MITLicense.It is designed for building web applications and APIs.It has been called the de facto standard server framework forNode.js.
const express =require("express")const app =express();// GET method route
app.get('/',function(req, res){
res.send('GET request to the homepage');});// POST method route
app.post('/',function(req, res){
res.send('POST request to the homepage');});
app.listen(3000,()=>{console.log("this App is running on port 3000")})
Express.js, or simply Express, is a back end web application framework forNode.js, released as free and open-source software under the MITLicense.It is designed for building web applications and APIs.It has been called the de facto standard server framework forNode.js.