node-服务器

时间:2021-12-01 12:10:54

原生:

 const http=require('http');
http.createServer((request,response)=>{
response.writeHead(200,{"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888)
 const http=require('http');
function onRequest(req,res){
res.writeHead(200,{"Content-Type":"text/plain"});
res.write('Hello World');
res.end();
}
http.createServer(onRequest).listen(8888);

koa:

 const Koa=require('koa');
const app=new Koa();
app.listen(8888)

express

 const express=require('express');
const http=require('http');
const app=express();
const server=http.createServer(app);
server.listen(8081);