Ossama Benallouch
Ossama Benallouch

Reputation: 97

Parse.com Node js failed to load json file

I'm trying to read a json file using node js/ express and deploying it to parseCloud but i keep getting

*Failed to load filters.json with: Could not find file filters.json *

here is my code:

var fs = require('fs');
var obj = JSON.parse(fs.readFileSync('cloud/filters.json', 'utf8'));

or this

var filterJson = require('cloud/filters.json');

thanks

Upvotes: 1

Views: 346

Answers (2)

ntoskrnl
ntoskrnl

Reputation: 1635

Looks like parse.com doesn't allow .json files. You can save your file as .js and load it as plain text file (doesn't work with require()).

var fs = require('fs');
var parsedObject = JSON.parse(fs.readFileSync('cloud/path/json_file.js'));

It looks ugly, but works for me. :)

Upvotes: 3

phts
phts

Reputation: 3925

Try to add ./

fs.readFileSync('./cloud/filters.json', 'utf8')

Upvotes: -1

Related Questions