I am building a hubot script and I want to load a yml file in it. I am using the yamljs npm package to read the YAML file.
The problem is that it allways says "No such file or directory" error. If i put the absolute path it works.
What I am missing? I am loading the file like this:
feeds = YAML.load('../feeds.yml');
Here is my directory structure:
Where are you executing the script from? In node, path files in fs
are relative to process.cwd()
.
Relative path to filename can be used, remember however that this path will be relative to process.cwd().
Sources: http://nodejs.org/api/fs.html , https://stackoverflow.com/a/16730379/1007263
Therefore, if your script is in the same directory as feeds.yml
, you should probably:
feeds = YAML.load('./feeds.yml');
Otherwise, there might be a bug in YAML. In this case, you can simply use path
to deliver the absolute path directly.
path.resolve('../feeds.yml')
Source: http://nodejs.org/api/path.html#path_path_resolve_from_to
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.