Install necessary dependencies with
npm i
The server starts on port 3000. Start the server with
npm start
Write minimal code for endpoints in app.js
. Write more logic in individual files in src/
.
The generic code for an endpoint is:
app.get('/get-endpoint', (request, response) => {
/* Simple get request
request.body should be in JSON. It is automatically parsed and can be
accessed like a JS object.
*/
logic here...
})
app.post('/post-endpoint', (request, response) => {
/* Simple post request
request.body should be in JSON. It is automatically parsed and can be
accessed like a JS object.
*/
logic here...
})
Write logic in individual files. Modules are written in the singleton design pattern.
module.exports = {
object code here...
}
Import them as a singleton object as
const mylogic = require('./src/logic-file.js')