自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(8)
  • 收藏
  • 关注

原创 NodeJS cookie 服务端操作

1. cookie 服务端操作 存储在浏览器的一段字符串,最大 5kb 每个域都可有一个 cookie, 跨域不共享 格式如: k1=v1; k2=v2; k3=v3; (可结构化) 每次 http 请求,cookie 都会随着传递到服务端 node 操作 cookie // 服务端操作 cookie const http = require('http') const server = http.createServer((req, res) => { // 设置 cookie

2020-07-06 16:49:02 534

原创 Mongodb学习笔记(二)

4. Mongoose–定义 Schema 在 db 文件夹中,新建 model.js 文件 // 数据模型 (规范数据格式) const mongoose = require('./db') // 定义 Schema (数据规范) const UserSchema = mongoose.Schema({ username: { type: String, required: true, // 必须有 unique: true // 唯一,不重复 }, p

2020-07-03 21:50:24 255

原创 Mongodb学习笔记(一)

1. 启动 Mongodb 数据库 在 Mongodb 的 bin 文件夹下打开控制台 输入 mongod.exe --dbpath D:\MongoDB\data\db 回车 重复步骤一,在控制台中输入 mongo.exe --port 27017 步骤三的服务可以按 ctrl C 停止,但步骤一的服务不能停止,是数据库的服务 2.nodejs连接mongodb 代码部分 // nodejs 连接 mongodb // 体会 nodejs 连接 mongodb 的能力,不会真正的用

2020-06-29 20:58:08 208

原创 Node慕课网学习笔记(五)

1. Koa2 中间件 为什么使用中间件 拆分业务模块,使代码清晰 统一使用中间件,使得各业务代码都规范标准 扩展性好,易添加、易删除 Koa2 业务代码都是中间件 所有的 app.use(…) 都是中间件 路由也是中间件(只不过限制了 url 规则) 每个中间件都有 async 函数 ,第一个参数是 ctx ,第二个参数是 next 运用中间件 app.js 中加入:(注册路由之前) // 模拟登陆(为了使用中间件) app.use(async (ctx, next) =>

2020-06-21 22:38:02 202

原创 Node慕课网学习笔记(四)

3. Koa2 处理 http 请求 返回字符串格式: ctx 即 res 和 req 的集合 const router = require('koa-router')() router.prefix('/api') // 前缀 // 定义路由:模拟获取留言板列表 router.get('/list', async (ctx) => { const query = ctx.query // req 功能 console.log('query', query) ctx.b

2020-06-20 16:30:35 203

原创 Node慕课网学习笔记(三)

1. koa2 的安装与使用 新建文件夹 npm init npm i koa --save 代码演示 新建 index.js 文件 const Koa = require('koa') // commonjs 模块化规范 const app = new Koa() // ctx context 上下文 app.use(async (ctx) => { ctx.body = 'hello world' }) app.listen(3000) // web server 监听的

2020-06-20 16:28:53 184

原创 Node慕课网学习笔记(二)

1.3 定义一个get路由 当 url 后带参数时,运用 url.split(’?’)[0] 方法把ur和参数分隔开。 req.method 方法判断使用的是 post 请求还是 get 请求。 const http = require('http'); const server = http.createServer((req, res) => { const url = req.url const path = url.split('?')[0] // /api/list?

2020-06-14 20:58:15 185

原创 Node慕课网学习笔记(一)

1. Node.js处理HTTP 1.1 node.js启动Web服务 const http = require('http') require 三个层级: 系统自带的模块 require('http') npm 安装 const _ = require('lodash') 自定义 require('./utils') const server = http.createServer(() = > { console.log('已经收到http请求') }) server.list

2020-06-12 23:30:21 211

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除