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 ...
随机推荐
- Gin 09 HTTP 重定向
gin http 重定向有两种方法,重写url 和 不重写的跳转.两种方法,gin 通过两个内置方法实现: demo package main import ( "github.com/gi ...
- springcloud学习03-spring cloud eureka(上)
对eureka一个大概介绍:https://blog.csdn.net/u010623927/article/details/88762525 这里面有个我做dubbo时的一个理解的错误:服务注册中不 ...
- 内网渗透----Token 窃取与利用
0x00 前言 在之前的文章<渗透技巧--程序的降权启动>介绍了使用 SelectMyParent 降权的方法,本质上是通过 token 窃取实现的.这一次将要对 token 窃取和利用做 ...
- java+eclipse安装及配置
一.JDK安装 0x00 下载JDK 首先我们需要下载java开发工具包JDK 下载地址:https://www.oracle.com/technetwork/java/javase/download ...
- Mybatis的XML文件调用静态方法
如果需要在Mapper文件中调用静态方法,需要 <choose> // 需要静态方法返回true还是false <when test="@staticClass@stati ...
- 你知道 Kafka 是如何做到消息的有序性?
kafka 中的每个 partition 中的消息在写入时都是有序的,而且单独一个 partition 只能由一个消费者去消费,可以在里面保证消息的顺序性.但是分区之间的消息是不保证有序的.
- Springmvc入门基础(四) ---参数绑定
1.默认支持的参数类型 处理器形参中添加如下类型的参数处理适配器会默认识别并进行赋值. 除了ModelAndView以外,还可以使用Model来向页面传递数据, Model是一个接口,在参数里直接声明 ...
- springboot-数据库访问之mybatis
选中mysqldirver,数据库驱动器 选中jdbc ,帮我们配置数据源,连接数据库 选中mybatis,持久层 <!-- 这个不是springboot官方出来的,是mybatis为了设备sp ...
- OGNL(Object-Graph Navigation Language)使用
OGNL表达式:https://www.jianshu.com/p/6bc6752d11f4 Apache OGNL:http://commons.apache.org/proper/commons- ...
- spring 支持哪些 ORM 框架?
Hibernate iBatis JPA JDO· OJB