Node.j中path模块对路径的操作
2018-02-13 14:15
239 查看
一.path模块 https://nodejs.org/docs/latest/api/path.html#path_path_join_paths
1.join方法 ==> 该方法将多个参数值字符串结合成一个路径字符串,使用方式如下:
path.join([path1], [path2], [...])
2. __dirname变量值代表程序运行的根目录。
var joinPath = path.join(__dirname, 'a', 'b', 'c'); console.log(joinPath); // F:\learning\CPC爬虫\a\b\c
3.下载某图片到指定目录
const request = require('superagent') const cheerio = require('cheerio') const fs = require('fs-extra') const path = require('path') function download() { const url2 = "https://imgsa.baidu.com/forum/w%3D580/sign=cbeba091a5014c08193b28ad3a7a025b/1ba6b90e7bec54e7141e3726b5389b504ec26ab4.jpg" const filename = url2.split('/').pop() const req = request.get(url2) req.pipe(fs.createWriteStream(path.join(__dirname, 'images', filename))) }
相关文章推荐
- Node.js中path模块对路径的操作
- Node.j中path模块对路径的操作
- Node.Js Path模块-文件或文件夹路径字符串操作
- Node.js中路径处理模块path详解
- Node.js中路径处理模块path详解
- Node之文件路径处理模块:path模块
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- Python os模块--路径、文件、系统命令等操作
- Python Imaging Library: ImagePath Module(图像路径模块)
- Node【模块】之path
- Node.js模块全局安装路径配置方法
- 【机器人学】机器人开源项目KDL源码学习:(3)机器人操作空间路径规划(Path Planning)和轨迹规划(Trajectory Planning)示例
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- Path类对路径字符串的操作
- Node.js Path模块
- python笔记13 - 系统模块,自定义模块的编写,模块的搜索路径,PYTHONPATH环境变量,模块的属性:__doc__, __all__,__file__,标准库模块,包
- node.js 使用fs模块对系统文件及目录进行读写操作
- 获取模块路劲,去除文件名,添加新的文件名,路径操作
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import(转)