摘要: 1.定义一个自定义模块 //当前这个文件,就是一个用户自定义模块console.log('加载了06这个模块') 2.引入定义的自定义模块 //使用require()方法加载其他模块时,会执行被加载模块中的代码 const m1 = require('./06m1模块化1') console.log 阅读全文
posted @ 2022-11-01 14:09 SadicZhou 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 1.创建clock文件夹,里面有index.hrml和对应的css文件 2.编写node代码 //1.1导入http模块 const http = require('http') //1.2导入fs模块 const fs = require('fs') //1.3导入path模块 const pat 阅读全文
posted @ 2022-11-01 13:45 SadicZhou 阅读(17) 评论(0) 推荐(0) 编辑
摘要: const http = require('http') const server = http.createServer() server.on('request',function(req,res){ //1.获取请求的URL地址 const url = req.url //2.设置默认的响应内 阅读全文
posted @ 2022-11-01 13:38 SadicZhou 阅读(12) 评论(0) 推荐(0) 编辑
摘要: const http = require('http') const server = http.createServer() server.on('request',function(req,res){ const url = req.url const method = req.method c 阅读全文
posted @ 2022-11-01 13:36 SadicZhou 阅读(13) 评论(0) 推荐(0) 编辑
摘要: req.app:当callback为外部文件时,用req.app访问express的实例 req.baseUrl:获取路由当前安装的URL路径 req.body / req.cookies:获得「请求主体」/ Cookies,//post请求参数获取 req.fresh / req.stale:判断 阅读全文
posted @ 2022-11-01 13:34 SadicZhou 阅读(26) 评论(0) 推荐(0) 编辑
摘要: //1.导入http模块 const http = require("http") //2.创建web服务器实例 const server = http.createServer() //3.为服务器实例绑定request实例,监听客户端的请求 server.on('request',functio 阅读全文
posted @ 2022-11-01 12:06 SadicZhou 阅读(16) 评论(0) 推荐(0) 编辑
摘要: const path = require('path') // ../会抵消一级路径 const pathStr = path.join('/a','/b/c','../','./d','e') console.log(pathStr) //凡是涉及到路径拼接的问题,都要使用path.join方法, 阅读全文
posted @ 2022-11-01 11:57 SadicZhou 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 如果使用相对路径,不在当前目录下通过其他目录来找到这个JS运行就会报错,当我们使用fs模块来操作文件时,我们如果使用相对路径的话,很容易出现路劲动态拼接错误的情况,JS在Node.js环境中运行的时候,执行的是当前所在的目录拼接上被操作文件的路径,这时如果我们不在当前文件的路径,无论怎么样手动添加补 阅读全文
posted @ 2022-11-01 11:44 SadicZhou 阅读(38) 评论(0) 推荐(0) 编辑
摘要: fs: file system 文件系统模块是node中内置模块用于本地文件或者目录的增删改查操作直接导入即可使用 const fs = require('fs') fs.readFile('./point.txt', 'utf-8', (err, data) => { if (err) { ret 阅读全文
posted @ 2022-11-01 11:30 SadicZhou 阅读(36) 评论(0) 推荐(0) 编辑