
Nodejs
LJ·START
这个作者很懒,什么都没留下…
展开
-
Nodejs中应用express创建web服务器
//创建商品路由器product.js,添加若干个路由,在服务器下引入并挂载app.js//引入express模块const express=require('express');//引入路由器模块const productRouter=require('./product.js');//创建web服务器const app=express();//设置端口app.listen(8080);//挂载路由器到web服务器app.use('/product',productRouter原创 2020-11-29 21:49:49 · 228 阅读 · 0 评论 -
应用Nodejs创建web服务器
//创建web服务器,设置端口,根据浏览器的URL做出响应 /index 响应'<h2>这是首页</h2>' /list 响应文件1.html /study 跳转到http://www.tmooc.cn 其他 响应404 not found//1.引入http模块const http=require('http');...原创 2020-11-29 17:29:55 · 324 阅读 · 0 评论 -
Node.js中用http模块创建web服务器
//1.引入http模块const http=require("http");//2.创建web服务器const app=http.createServer();//3.设置端口号app.listen(8080);//4.添加请求事件app.on('request',(req,res)=>{ //4.1设置响应的状态码和头信息 res.writeHead(200,{ 'Content-Type':'text/html;charset=utf-8'}); //4..原创 2020-11-29 17:11:12 · 424 阅读 · 1 评论 -
如何快速使用Nodejs创建web服务器?
//如何使用Nodejs创建web服务器//引入http模块const http=require('http');//创建web服务器//把创建好的web服务器用常量const存下来(所有常量的地方也能用变量),将web服务器起名为appconst app=http.createServer();//设置端口app.listen(8080);//1024~65535//添加请求事件:一旦浏览器发来请求,自动监听到,执行回调函数,做出响应app.on('request',(req.原创 2020-09-20 22:50:33 · 201 阅读 · 0 评论