【发布时间】:2019-02-08 16:47:08
【问题描述】:
我的目录结构如下:
home/
├── module1/
│ ├── index.js
│ └── file.csv
└── module2/
└── index.js
模块 1 index.js 的代码使用名为 csvtojson 的节点模块读取 file.csv。 module2/index.js 需要 module1/index.js。
当我直接从 module1 运行代码时,一切正常并且文件被成功读入。但是,当我在 module2 中运行代码时,我得到一个“文件不存在”。错误。我是否需要明确地将所有路径设为绝对路径?
【问题讨论】:
-
请通过edit将您的问题设为minimal reproducible example,以包含相关代码。
-
请至少提供您所有的
require()和fs.readFile()行以及使用的路径。
标签: javascript node.js node-modules relative-path