How do I return the reply to the data using Express?

advertisements

I am trying to run .get on a JSON file I've set up located at /scripts/src/data/*.json when I make the request I set the headers but I'm not sure how I actually return the resulting data or where I can view this request. Can someone offer any help?

JS

server.get('/scripts/src/data/*.json', function(req, res) {
    res.setHeader("Content-Type", "application/json");

    // return ??
});


You could use static middleware to serve your json files ,

server.use(express.static(__dirname + "/scripts/src/data"))
//other routes

In client side , you just should request GET localhost:port/file.json