// 无论使用什么模块,都要先加载const path = require('path');// ------------------- 获取路径中的后缀 ---------------------------// console.log(path.extname('./a/b/index.html')); // .html// console.log(path.extname('http://www.itcbc.com:8080/js/index.js')); // .js// ------------------- 智能拼接路径 -----------------------------// console.log(path.join('a', 'b', 'c')); // a/b/c// console.log(path.join('a', 'b', 'c', 'index.css')); // a/b/c/index.css// a里面有b,b里面有../c,言外之意,c和b同级。// console.log(path.join('a', 'b', '../c', 'index.js')); // a/c/index.js// __dirname 永远表示当前js文件的绝对路径console.log(path.join(__dirname, 'css', 'demo.css')); // /Users/tangfengpo/Study/123/Node01/code/css/demo.css
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。