Zulu
Zulu

Reputation: 81

ReferenceError: loadJSON is not defined

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.

Upvotes: 0

Views: 4837

Answers (1)

CaptEmulation
CaptEmulation

Reputation: 4586

Recent versions of NodeJS can import a JSON file directly:

const words = require('./words.json');

Upvotes: 1

Related Questions