上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页
摘要: 1. 同步错误 app.get('/', (req, resp) => { if(!req.query.name) { throw new Error('name query parameter required'); } resp.end('ok'); }); 2. 异步错误 异步错误,发生在回调 阅读全文
posted @ 2022-02-21 14:55 箫笛 阅读(510) 评论(0) 推荐(0)
摘要: 每个路由函数或中间件都接收一个response响应对象,路由函数通过调用响应对象的方法,可以将响应发送到客户端,并结束请求处理。 如果路由函数未调用响应对象的任何方法,则客户端请求将被挂起,直到客户端超时。 1. 设置响应状态码 resp.status(statusCode) app.get('/' 阅读全文
posted @ 2022-02-20 21:44 箫笛 阅读(152) 评论(0) 推荐(0)
摘要: 中间件以及路由函数接收的第一个参数就是request对象 1. request对象常用属性 method 请求方法 path 请求路径 (GET参数不包含在path中) url 请求url (除域名外的完整URL,包含GET参数) query GET参数对象 params 路由参数对象 header 阅读全文
posted @ 2022-02-20 19:40 箫笛 阅读(121) 评论(0) 推荐(0)
摘要: 1. 定义路由 app.METHOD(PATH, HANDLER); // get 方法 app.get('/', (req, resp) => { resp.send('GET method'); }); // post 方法 app.post('/', (req, resp) => { resp 阅读全文
posted @ 2022-02-19 14:49 箫笛 阅读(213) 评论(0) 推荐(0)
摘要: 中间件是可以访问请求对象,响应对象以及next()函数,可以完成如下任务: 执行任何代码 更改请求和响应对象 结束请求处理 调用下一个中间件 1. 全局中间件 //创建应用 const express = require('express'); const app = express(); //创建 阅读全文
posted @ 2022-02-19 14:35 箫笛 阅读(170) 评论(0) 推荐(0)
摘要: 1. 初始化项目 mkdir express-example cd express-example npm init -y npm install body-parser express ejs --save 2. 编写入口文件 // 导入express 模块 const express = req 阅读全文
posted @ 2022-02-19 11:19 箫笛 阅读(120) 评论(0) 推荐(0)
摘要: 1. 条件测试格式 简单条件测试 if [ condition ] then commands fi 注意condition条件表达式在前后方括号之后和之前各有一个空格,否则会出现语法错误 逻辑与条件测试 if [ condition1 ] && [ condition2 ] then comman 阅读全文
posted @ 2022-02-14 16:24 箫笛 阅读(84) 评论(0) 推荐(0)
摘要: 1. if-then 语句 if command then commands fi 2. if-then-else 语句 if command then commands else commands fi 3. if-then-elif-then-else 语句 if command1 then c 阅读全文
posted @ 2022-02-14 15:38 箫笛 阅读(42) 评论(0) 推荐(0)
摘要: 设置 conda 环境是否在命令行自动开启 conda config --set auto_activate_base false 配置 conda 增加频道 conda config --add channels bioconda 删除频道 conda config --remove channe 阅读全文
posted @ 2022-02-12 22:00 箫笛 阅读(152) 评论(0) 推荐(0)
摘要: 1. 函数默认退出状态码 function isDirExist { local dir=$1 ls $dir } dir=/path/test/ isDirExist "$dir" if [ $? -eq 1 ] then echo "The $dir is not exist" exit fi 阅读全文
posted @ 2022-02-12 14:18 箫笛 阅读(64) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页