0

Right now I'm browserifying my code in the gulpfile, and sending it to the appropriate location. however if I want to parse a json file and display it within index.html...

it returns this error:

Uncaught TypeError: require(...).readFileSync is not a function

Here is my code http://pastebin.com/n0BJfZG9 of my gulpfile and app.js

Am I missing something? Why can't I use normal node modules for this kind of thing?

2
  • 1
    I'm guessing you are using fs. You need to import just fs then use the fs.readFileSync() Commented Jan 25, 2016 at 19:05
  • @The added code. sorry about that Commented Jan 25, 2016 at 19:08

1 Answer 1

5

You should be able to require your JSON file directly in node:

var myJson = require('./path/to/file.json');

// log to confirm output
console.log(JSON.stringify(myJson));

This assumes file.json is raw JSON, along the lines of:

{
  "property": "value",
  "property2": "value2"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.