解决js异步的方法有很多种,今天就讲解一下如何解决js中的异步问题。 在讲解异步解决办法之前我们需要知道什么是异步。定时器、AJAX、事件绑定等都会引起js的异步行为,今天用js中的定时器为例来讲解,看下题。 ...
node
async函数
一,async函数介绍 1.async函数是异步的一种方案,可以让异步的操作同步执行。 二,async函数基本形式 1.声明形式:在函数前加上关键字async 表示该函数是一个async 函数 async function fn(){ awai...
nodejs express multer 上传图片
安装依赖 npm install --save multer multerConfig.js // 1. 引入依赖 const multer = require("multer"); const md5 = require("md5"); const fs = require("fs"); // 2. 引入工具 const path = r...
Express使用express-validator
在Express中验证传入的数据。 假设您有一个POST接口,它接受名称、电子邮件和年龄参数: const express = require('express') const app = express() app.use(express.json()) app.post('/form', (re...
express+svg-captcha验证码实现及验证
安装: npm install --save svg-captcha svg-captcha依赖session存储验证码信息 express-session是express中比较常用的处理session的中间件,使用npm安装 npm install express-session --save sess...
使用sequelize实现关联查询
关联查询包含一对多和多对一的映射关系,一对多的API为belongsTo,多对一的API为hasMany。使用sequelize进行关联查询时,要根据具体情况选择用哪一个映射关系,因为这其中涉及左右连接、内外连接的性能问题。下面...
node express项目中使用了connect-history-api-fallback中间件后所有get失效
用了connect-history-api-fallback中间件后所有的get请求都会变成index,所以get请求根本没有执行,设置rewrites就行了 const history = require('connect-history-api-fallback') app.use(history({ rewr...
js中的回调函数callback
概念:A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. from MDN… 翻译过...
mac 下常用快捷键,mac启动ftp
Command + K清屏 Command + T新建标签 Command + M最小化窗口 Command +W 关闭当前标签页 Command + S 保存终端输出 Command + D 垂直分隔当前标签页 Command + Shift + D 水平分隔当前标签页 ...
node HTTP模块-区分发送的请求是GET还是POST请求
服务端区分用户发送的是GET请求和POST请求 通过 HTTP 模块的 http.IncomingMessage 类的 .method 属性即可区别 具体源码如下所示 let http = require("http"); // 1.创建一个服务器实例对象 let serve...