What i'm trying to do is to save all the static of my website in a json file that i want to read in angular, i was thinking about two ways of do it:
- Call a json file directly from AngularJS
- Send the json file from node to AngularJS
I don't know how to do either of them, i've tried the second way like this(no luck):
Nodejs code:
app.get( '/content', function ( require, response ) {
response.setHeader('Content-Type', 'application/json');
response.json( readJSONFile( './client/content.json', function ( err, json ) {
if ( err ) {
throw err;
}
console.log( json );
} )
)
} );
function readJSONFile( filename, callback ) {
require( "fs" ).readFile( filename, function ( err, data ) {
if ( err ) {
callback( err );
return;
}
try {
callback( null, JSON.parse( data ) );
} catch ( exception ) {
callback( exception );
}
} );
}
When i access to localhost:3000/content
and i check the network on the browser the file is sent, but i can't see the data in the preview tab, not sure of what i'm doing wrong...
Also how could i make a service to get this data from the server in AngularJS?