随笔分类 - nodejs
摘要:-- 安装mysql模块 npm i mysql -连接数据库 const mysql = require('mysql') //建立与mysql数据库的连接关系 const db = mysql.createPool({ host:'127.0.0.1',//数据库的ip地址 user:'root
阅读全文
摘要:-中间件概念 -中间件特指业务流程的中间处理环节 -express中间件的格式 //中间件的形参列表中,必须包含next参数,而路由处理函数中只包含req和res app.get('/',(req,res,next)=>{ next() }) -next函数的作用 next函数是实现多个中间件连续调
阅读全文
摘要:-路由的概念 -express中的路由 在express中,路由指的是客户端请求与服务器处理函数之间的映射关系。 express中的路由由3部分组成,分别是请求的类型,请求的URL地址,处理函数,格式如下: //匹配get请求,路径为/index app.get('/index',(req,res)
阅读全文
摘要:-express的基本使用 -下载express npm install express --save -调用 const express = require('express') const app = express() app.listen(80,()=>{ console.log('serv
阅读全文
摘要:1.引入http模块 const http = require('http') 2.调用createServer()创建服务器 const server = http.createServer() 3.调用on绑定request事件 server.on('request',()=>{ console
阅读全文
摘要:-path.join() -作用:把多个路径片段拼接成完整的字符串 -代码示例: const path = require('path') const fs = require('fs') // ../会抵消掉前面路径 const url = path.join('/a','/b','/ab/c',
阅读全文
摘要:-fs.readFile() -用来读取指定文件的内容 -语法:fs.readFile(path,options,callback) -path:必选参数,要读取的文件路径 -options:可选参数,以什么编码格式来读取文件 -callback:必选参数,读取文件后,通过回调函数拿到读取的结果 -
阅读全文

浙公网安备 33010602011771号