Node
文章平均质量分 50
SignalFire
这个作者很懒,什么都没留下…
展开
-
Node搭配Express
一、创建服务器const express = require("express")const app = express();app.listen(3000);console.log("服务器启动,端口3000......");二、app.get()服务端请求数据get("/路由名",callback)app.get("/",(req,res)=>{ res.send("hi")})next参数:get(路径,callback,next)当有nex...原创 2022-05-31 15:52:26 · 174 阅读 · 0 评论 -
Node异步编程与Promise
同步API与异步API同步API:当前API完成后才会执行下个API异步API:1.当前API的执行不会阻塞后序API的执行console.log(1);setTimeout(()=>{ console.log(2);},1000);console.log(3);//1 3 22.无法通过返回值的方式拿到函数执行结果只能通过回调函数(回调函数:自己定义函数供其他人调用)function getMsg(callback){ s...原创 2022-05-30 11:21:04 · 66 阅读 · 0 评论 -
Node MongoDB
连接数据库const mongoose = require("mongoose");mongoose.connect("mongodb://localhost/db530") .then(()=>{console.log("connect success")}) .catch(err=>console.log(err,"connect fail"));创建规则const courseSchema = new mongoose.Schema({...原创 2022-05-30 11:20:20 · 81 阅读 · 0 评论 -
Node文件模块fs与路径模块path
path模块路径拼接不同操作系统的路径分割符不统一fs读取文件:readFile("文件路径"[,"utf8"],callback);fs.readFile(path.join(__dirname,"a.txt"),"utf8",(err,data)=>{ if(err){ console.log(err);}else{ console.log(data);...原创 2022-05-29 11:04:53 · 120 阅读 · 0 评论 -
Node的模块化开发
JavaScript开发的弊端文件依赖和命名冲突exports与module.exportsexports是module.exports的别名,最终以module.exports为准exports 导出let num = 12;let fn = function(){ console.log("out.js中的函数")}exports.num = num;exports.fn = fn;module.exports导出let num = 12;le...原创 2022-05-29 10:11:38 · 79 阅读 · 0 评论