- Create the routes file using the boilerplate code below in the folder
./src/routes
.
const config = require("../config/config");
const version = config.get("version");
const controller = require("../controllers/CONTROLLER_NAME");
module.exports = function (app) {
// This route creates a game and returns a joinable url and admin access token.
app.route("/api/" + version + "/ROUTE_SLUG").get(controller.CONTROLLER_FUNCTION);
};
- Then Create the controller in the folder
./src/controllers
using the boilerplate code.
// Require config
const config = require("../config/config");
// Import JWT
var jwt = require('jsonwebtoken');
// CreateGame function creates a yoinked game when triggered.
const CONTROLLER_FUNCTION = (req, res) => {
return res.send({ message: "Hello World!" });
};
// export all functions
module.exports = {
CONTROLLER_FUNCTION,
};
- Add the route file in the directory:
./src/config/express.js
add the route file using the code below.
require("../routes/ROUTE_FILE")(app);
- Make the new model using the code below and save it inside
./src/models/
using conventionname.model.js
,
const mongoose = require("mongoose");
const SCHEMA_NAME = new mongoose.Schema({});
mongoose.model(`MODEL_NAME`, SCHEMA_NAME);
- Add the import inside
./src/config/db.js
at the top of the page, using the coderequire("../models/name.model")
- Add the key and value to the model located inside
./src/models/
, - Go to
./src/controllers/database.controller.js
and add the new value to be saved to the database insidesaveReviewToDatabase
,