kockburn
kockburn

Reputation: 17636

Error: ENOENT, no such file or directory in meteor

Description of the problem:

Trying to import JSON file when server starts up.

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
    var fs = Npm.require('fs');
    Videos = fs.readFileSync("public/toc_vd_en.json", "utf8");
  });
}

Getting a Error: ENOENT, no such file or directory 'public/toc_vd_en.json'

File structure:

Error: ENOENT, no such file or directory

Question:

I believe I'm giving the correct relative path. What is causing this error?

Upvotes: 0

Views: 2878

Answers (1)

Kevin Simple
Kevin Simple

Reputation: 1213

mate, try this:

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
    var base = process.env.PWD;
    var fs = Npm.require('fs');
    Videos = fs.readFileSync(base + "/public/toc_vd_en.json", "utf8");
  });
}

Upvotes: 6

Related Questions