【发布时间】:2020-10-31 09:37:20
【问题描述】:
我想使用myFunction()获取文件
如果用户将相对路径作为函数参数传递,如何获取文件
../somewhere/index.js
import {myFunction} from "../pathTo/app.js";
myFunction("../relative/path/file.txt");
app.js
export const myFunction = (path) => {
fs.readFile(path); //=> How to get the file here
};
【问题讨论】:
-
您可以使用
__dirname + "/relativ/path"或类似const path = require('path'); path.resolve(../relative/path/file.txt")的方式获取绝对路径
标签: javascript node.js typescript path fs