Serve static .json file to Nodejs using expressjs and serve-static

I have the following code:

...
var servceStatic = require("serve-static");
var app = express();

app.use(express.compress());
app.use(servceStatic('static'));
...

      

Somehow it manages to serve all files except those that end in ".json". Why is this?

+3


source to share


1 answer


you don't need this service-static module because it's built into express:

create a shared folder and just add this line to your code after you instantiate express:



var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));

      

This should transfer all your files including JSON files.

+1


source







All Articles