
node
皮卡卡卡
一个正在学习前端小萌新~
展开
-
node_ejs 模板引擎
node_ejs 模板引擎中文文档https://ejs.bootcss.com/#install案列1:通过ajax方式请求后端数据后端文件:01.jsconst express = require("express");let app = express();app.listen(4567);app.get("/",(req,res)=>{ res.sendFile(require("path").join(__dirname,"./test.html"));//原创 2021-03-24 20:44:33 · 138 阅读 · 0 评论 -
node_http服务: express 3
node_http服务: express 3nodemon 热更新安装了nodemon 这个包后,每次后端发生改变后,不需要每次关闭重启接口文件。 安装:npm i nodemon -g 然后不用node app.js来启动接口文件,用:nodemon app.js 来启动接口文件就可以了静态目录\静态文件设置一个中间件,来设置一个存放静态文件的文件夹,就是静态目录。const express = require("express");const path = require("p原创 2021-03-24 20:42:41 · 116 阅读 · 0 评论 -
node _http服务: express 2
#node _http服务: express 2中间件const express = require("express");const app = express();app.listen(7878);/** 中间件* 处理路由请求的函数叫做中间件* 如果一个路由经过多个中间件函数,那么前面的中间件函数都必须有next()才会进入下一个中间件函数* app.use()可以给所有的路由绑定一个中间件** 不能给前端(send / sendFile / end /...)原创 2021-03-24 20:40:33 · 221 阅读 · 0 评论 -
node_http服务: express 1
node_http服务: express 1express 包:/命令行中配置环境及安装 包:* npm init -y* npm i express -S*/引入包*/const express = require("express");const path = require("path");/创建一个服务*/let app = express();************************************************************原创 2021-03-11 18:50:53 · 153 阅读 · 0 评论 -
node_爬虫2
node_爬虫2小说爬取案列const request = require("request");const cheerio = require("cheerio");const fs = require("fs");request.get( "http://book.zongheng.com/showchapter/907701.html", //单个地址直接引号即可 (err,res,body)=>{ //err:一般为错误报告原创 2021-03-11 18:49:07 · 104 阅读 · 0 评论 -
node_爬虫1
node_爬虫1request包安装request包 npm i request -S引入request包: const request = require("request");使用request包: request.get({ url : "https://www.baidu.com/" },(err,res,body)=>{ /*回调函数 * err:错误对象 * res:响应相关一些信息原创 2021-03-11 18:48:30 · 141 阅读 · 0 评论 -
node_npm
npm初始化项目文件夹npm init /需要一步一步配置npm init -y /直接一键完成----初始化,用npm来帮助你管理项目,会生产一个package.json的文件 关于package.json文件 * 项目进行中,任何时刻不允许删除package.json * 会记录当前项目各种依赖 { "name": "abc", "version": "1.0.0", //版本号 "description": "", //描述原创 2021-03-11 18:46:40 · 115 阅读 · 0 评论 -
node_fs模块
node_fs模块文件内容读取:fs.readFile();const fs =require("fs");/* 文件内容读取: 参数1:文件路径和名字 参数2:可选,文件的格式类型 参数2:所有异步函数都有的回调函数=> 第1个参数:错误对象 第2个参数:读取到的数据内容*/fs.readFile( "./007.txt", "utf8", (err,data)=>{ if (原创 2021-03-11 18:45:28 · 161 阅读 · 0 评论