Install nodejs and npm (NodePacketManager) via sudo yum install nodejs npm
NodeJS is basically "Javascript" for servers. You can start the commandline-version by simply typing node.
Express is a minimalistic web framework for NodeJS. Install it via sudo npm install express.
Further Documentation of 'express' can be found at npmjs.com/package/express.
Now, for example, you can create a file named "simple.js" and paste the following example-code inside:
const express = require("express") const app = express() app.get("/", function(req, res){ res.send("Hello World!") }) app.listen(3000)
We can now add to the example from above.
We'll make a new 'route' (link) for our app which takes an ID and returns data from that.
const express = require("express") const app = express() var rdata = ["Apple","Strawberry","Cherry","Banana"] app.get("/", function(req, res){ res.send("Hello World!") }) app.get("/:id", function(req, res){ if(req.params.id < rdata.length){ res.send("Data: "+_data[req.params.id]); }else{ res.send("ID "+req.params.id+" can't be found."); } }) app.listen(3000)
const fs = require("fs"); var rdata = JSON.parse(fs.readFileSync("data.json","utf8"));
The example above is very simple and minimalistic.
The first thing you should look into next would be the MVC (Model View Controller) architecture that you should write for express. This splits the get-data, URL-Route, and send-data part into different files, because in our above example they are all in one file.
Another good idea would be to look into modules that easily connect your database to the NodeJS REST server. Getting data from JSON files isn't the best idea for a big amount of ever-changing data.