Controllers page
CREATE A FOLDER CALLED controller IN THE src FOLDER
CREATE A FILE CALLED index.js IN THE controller folder
ADD THE FOLLOWING CODE
This is a simple function to be used with Thunder Client
or Insomnia to test the Server is receiving a request and giving
a response
Create a file called controllers.js
and add the following code to it
exports.testGet = (req, res) => {
res.send("Reply from GET");
}
NOW RUN npm i nodemon and add this line to package.json
"dev" : "nodemon src/server.js"
after the test line called test
DON'T FORGET THE COMMA AT THE END OF test OR YOU WILL GET AN ERROR
You can now test by first running
npm run dev
in the terminal
If you used PORT 5000 then you should run:
http://localhost:5000/testGet
You can choose any port, for example if you
wanted to use port 3000, run the following:
export PORT=3000
Next we will create a model
Model