Create New Endpoint

Model

The model will contain the definition of the mongoose schema that represents the document on MongoDB

models/user.model.js

models/user.model.js

Controller

Controllers will contain the functions that handle the various request methods for the endpoint.

controller/users.js

controller/users.js

Routes and Index.js

The routers will route the endpoints for a specific api. It will be appended to the server’s baseURL found it .env and the api path defined in the server’s index.js file.

index.js

index.js

app.use() tells the app to run the routes/users.js userRouter function (which contains methods handling requests), on the path /users.

routes/users.js

routes/users.js

routes/tasks.js

routes/tasks.js

For example, to (get) a new user, the url will be baseURL + /users + /get = baseURL/users/get

To (post) a new task, the url will be baseURL + /tasks + / = baseURL/tasks