I am trying to require() this JSON file.
{
"info" : function (request) {
var i = "<pre>";
i+= "current working directory: " + process.cwd() + "\n";
i+="request url: " + request.url + "\n";
i+= "</pre>";
return i;
}
}
Using this line
var render = require('./render.json');
But I get an exception from the JSON file of : Unexpected token u
What am I doing wrong please ?
The following works in a browser. Which I would expect, since a function is a object. And nodejs docs suggests JSON can be a module: http://nodejs.org/api/modules.html#modules_file_modules
<html>
<head>
</head>
<body>
<script>
var a = {
"b" : function(msg){
alert(msg);
}
}
a.b("Hello");
</script>
</body>
</html>