0

I am using Atom, and I have node.js installed and npm install -g json Everything went okay with the installation and the version prompted on the cmd window. I'm running a server through nodemon server.js

 //server.js

  var words = loadJSON('words.json');

  //words.json

  {
   "rainbow": 5,
   "cat dog": 6
  }

How come I keep getting this reference error? I also have the p5 library that has the loadJSON method so I am not sure where else can go wrong.

2
  • p5 won't run on node server side as it is dependent on accessing the window object. Have provided you with another way of reading the file below. Let me know if this solved your issue Commented Aug 18, 2017 at 22:34
  • Is this browser/client code or node/server code? Commented Feb 21, 2021 at 3:32

1 Answer 1

1

Recent versions of NodeJS can import a JSON file directly:

const words = require('./words.json');
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.