首页 > Web开发 > 详细

06-Node.js学习笔记-创建web服务器

时间:2019-12-20 01:44:46      阅读:103      评论:0      收藏:0      [点我收藏+]

创建web服务器

//引用系统模块
const http = require('http');
//创建web服务器
const app = http.createServer();
//当客户端发送请求的时候
app.on('request',(req,res)=>{
    //请求方式req.method
    console.log(req.method)
    if(req.method=="GET"){
        res.end("GET")
    }else if(req.method=="POST"){
        res.end("POST")
    }
    //响应
    //res.end('<h1>hi,user</h1>');
});
//监听3000端口
app.listen(3000);
console.log('服务器已启动,监听3000端口,请访问localhost:3000')

06-Node.js学习笔记-创建web服务器

原文:https://www.cnblogs.com/foreverLuckyStar/p/12070826.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!