express js how to post to .json file code example
Example 1: nodejs json data serving
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const fs = require('fs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const routes = require('./routes/routes.js')(app, fs);
const server = app.listen(3001, () => {
console.log('listening on port %s...', server.address().port);
});
Example 2: nodejs json data serving
{
"1": {
"name": "king arthur",
"password": "password1",
"profession": "king",
"id": 1
},
"2": {
"name": "rob kendal",
"password": "password3",
"profession": "code fiddler",
"id": 2
},
"3": {
"name": "teresa may",
"password": "password2",
"profession": "brexit destroyer",
"id": 6
}
}