NodeJs学习日报day6——路由模块
const express = require('express')
const app = express()
app.get('/user', function(req, resp) {
resp.send({name: 'Cra2iTeT', age: 20, gender: '男'})
})
app.get('/', function(req, resp) {
console.log(req.query);
// req.query可以接收参数默认为空
})
// :id是一个动态参数,id可更换,是匹配后的属性名
app.get('/user/:id', function(req, resp) {
// 获取动态匹配到的参数,默认为空
console.log(req.params);
resp.send(req.params)
})
app.post('/user', function(req, resp) {
resp.send({name: 'Cra2iTeT', age: 20, gender: '男'})
})
app.listen(8080, () => {
console.log('express server running at http://12700.0.1:8080');
})
const express = require('express')
const app = express()
// 在这里调用static方法,对外提供静态资源
// 同时托管多个文件夹时,文件夹内有同名文件则优先访问先导入的资源
app.use(express.static('../day2/clock'))
// 给取别名,要访问就得加别名路径
// app.use('/public', express.static('../day2/clock'))
app.get('/get', function(req, resp) {
resp.send('Hello world')
})
app.post('/post', function(req, resp) {
resp.send('Post')
})
app.listen(8080, () => {
console.log('express server running at http://12700.0.1:8080');
// console.log('测试是否自动重启');
})
const express = require('express')
const router = express.Router()
// 挂载具体路由模块
router.get('/user/list', function(req, resp) {
resp.send('Get')
})
router.post('/user/add', function(req, resp) {
resp.send('Post')
})
module.exports = router
let express = require('express')
let app = express()
const router = require('./router')
app.use(router)
app.listen(8080, () => {
console.log('express server running at http://12700.0.1:8080');
})
NodeJs学习日报day6——路由模块的更多相关文章
- NodeJs学习日报day8——接口编写
今天看了黑马NodeJs中关于接口编写以及跨域问题的视频
- NodeJs学习日报day9——操作数据库
const mysql = require('mysql') const db = mysql.createPool({ // 数据库的ip地址 host: 'localhost', user: 'r ...
- NodeJs学习日报day7——简单中间件
const express = require('express') const app = express() const mw = function(req, resp, next) { cons ...
- NodeJs学习日报day5——导入模块
const { match } = require("assert") function dateFormat(dataStr) { const dt = new Date(dat ...
- NodeJS学习日报day4——模块化
// console.log(module); // 执行顺序不同,结果也不同 // module.exports = { // name : 'Cra2iTeT', // hi() { // con ...
- NodeJs学习日报——day3
// 导入模块 const http = require('http') // 创建web服务器实例 const server = http.createServer() // 为服务器实例绑定req ...
- Python学习记录day6
title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...
- Nodejs学习路线图
前言 用Nodejs已经1年有余,陆陆续续写了48篇关于Nodejs的博客文章,用过的包有上百个.和所有人一样,我也从Web开发开始,然后到包管 理,再到应用系统的开发,最后开源自己的Nodejs项目 ...
- Nodejs学习笔记(四)——支持Mongodb
前言:回顾前面零零碎碎写的三篇挂着Nodejs学习笔记的文章,着实有点名不副实,当然,这篇可能还是要继续走着离主线越走越远的路子,从简短的介绍什么是Nodejs,到如何寻找一个可以调试的Nodejs ...
随机推荐
- 6月5日 python复习 模块
"""1. os和sys都是干什么的?2. 你工作中都用过哪些内置模块?3. 有没有用过functools模块?"""1. os 系统相关 ...
- Delaunay三角剖分及MATLAB实例
https://blog.csdn.net/piaoxuezhong/article/details/68065170 一.原理部分 点集的三角剖分(Triangulation),对数值分析(如有限元 ...
- Oracle问题解决记录
一.前言 oracle这么一个庞大的东西,出点问题真是太常见了.开个博客,用于记录遇到的问题吧. 持续更新. 二.问题列表 归档日志满,引起的问题. 一台服务器,用了很久了,某天,出现了磁盘空间占满的 ...
- String 和StringBuffer、StringBuilder的区别?
Java提供了:String.StringBuffer和StringBuilder,它们都是CharSequence的实现类,都可以作为字符串使用. String代表了字符序列不可变的字符串:而Str ...
- ubuntu18.04设置开机自启Django
设置开机自启: rc-local.server [Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.l ...
- Kafka 判断一个节点是否还活着有那两个条件?
(1)节点必须可以维护和 ZooKeeper 的连接,Zookeeper 通过心跳机制检查每 个节点的连接 (2)如果节点是个 follower,他必须能及时的同步 leader 的写操作,延时不能太 ...
- Dubbo 支持分布式事务吗?
目前暂时不支持,可与通过 tcc-transaction 框架实现 介绍:tcc-transaction 是开源的 TCC 补偿性分布式事务框架 Git 地址:https://github.com/c ...
- mac 添加java_home 和启动es
转:https://www.cnblogs.com/wxmdevelop/p/9935797.html p.p1 { margin: 0; font: 11px Menlo; color: rgba( ...
- spring-boot 注解集合
@Configuration 用于定义配置类,可替换XML配置文件,被注解的类内部包含一个或多个@Bean注解方法.可以被AnnotationConfigApplicationContext或者Ann ...
- WebSQL是什么?
WebSQL是客户浏览器端的结构化的关系数据库.这是浏览器内部的本地RDBMS,你可以在这个本地RDBMS上执行SQL查询.