// 使用 `path.join()` 而不是 `+` 确保Windows也能正常工作
const path = require('path')
// 找到基于调用点的相对路径,对于命令行程序(CLI applications)非常实用
path.join(process.cwd(), 'my-dynamic-file')
// 或者
path.resolve('my-dynamic-file')
// 基于一个文件找到另外一个文件
path.join(__dirname, 'my-package-file')
const path = require('path')
const fs = require('fs')
// read a file and pipe it to the console
fs.createReadStream(path.join(__dirname, 'my-file'))
.pipe(process.stdout)
const path = require('path')
const fs = require('fs')
// cat ./my-file > ./my-other-file
fs.createReadStream(path.join(__dirname, 'my-file'))
.pipe(fs.createWriteStream(path.join(__dirname, './my-other-file')))
const rimraf = require('rimraf')
const path = require('path')
rimraf(path.join(__dirname, './my-directory'), err => {
if (err) throw err
})
const mkdirp = require('mkdirp')
const path = require('path')
mkdirp(path.join(__dirname, 'foo/bar'), err => {
if (err) throw err
})
const readdirp = require('readdirp')
const json = require('JSONStream')
const path = require('path')
// recursively print out all files in all subdirectories
// to the command line. The object stream must be
// stringified before being passed to `stdout`.
readdirp({ root: path.join(__dirname) })
.pipe(json.stringify())
.pipe(process.stdout)
const findup = require('findup')
const path = require('path')
// recurse up all files relative to __dirname and find
// all `package.json` files.
findup(path.join(__dirname), 'package.json', (err, res) => {
if (err) throw err
console.log('dir is: ' + res)
})
const pump = require('pump')
const fs = require('fs')
// oh no, no errors are handled!
fs.createReadStream('./in.file').pipe(fs.createWriteStream('./out.file'))
// that's better, we're handing errors now
const rs = fs.createReadStream('./in.file')
const ws = fs.createWriteStream('./out.file')
pump(rs, ws, err => {
if (err) throw err
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有