Skip to content

Instantly share code, notes, and snippets.

@qcom
Created August 17, 2012 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qcom/3380327 to your computer and use it in GitHub Desktop.
Save qcom/3380327 to your computer and use it in GitHub Desktop.
SyntaxError: Unexpected token
// For some reason this code yields the following error upon execution:
// undefined: 1
//
// ^
// SyntaxError: Unexpected token
// Commenting out the JSON.parse() solves the error, but I don't understand what's wrong with the line
var fs = require('fs');
var files = fs.readdirSync('./output/');
var products = [];
for (var i = 0; i < files.length; i++) {
var path = './output/' + files[i];
var product = JSON.parse(fs.readFileSync(path, 'utf8'));
products.push(product);
}
exports.products = products;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment