NodeJS is not a web server.
However, you can easily add dependencies to provide such
capabilities.
e.g. express, koa, or hapi.
So far, you've got [something like]:
const fs = require('fs');
fs.readFile('data.json', (e, data) => {
if (e) throw e;
console.log(data);
});
You could use express as follows (note: if you have not
already run npm init, do so and provide sensible defaults):
npm init
npm install --save express
Then, create a file, app.js, to serve you're data, e.g.:
const fs = require('fs');
const express = require('express');
const app = express();
app.use('/', (req, res) => {
if (e) throw e;
// **modify your existing code here**
fs.readFile('data.json', (e, data) => {
if (e) throw e;
res.send(data);
});
});
app.listen(5555);
Launch your node "web server":
node app.js
Finally, point your browser to:
http://localhost:5555/