Create Server Routes
So far, you have only one index route: Hello World. Create more routes so that you can retrieve all the movies from the database and save them.
Set Up the Middleware
Set up the middleware before all the routes, as follows:
Set up Secrets, Bundling, and Watching
Recall that you ran the create
command on the index.js
file earlier. Now perform these tasks:
Bundle two files (
index
anddb
).Specify the secrets (
env
).Watch for the changes.
Run this command line for them all:
Grab the URL from the database home:
Create A Movie Route
Add the following route immediately after the /
route:
The above code does the following:
Create a new movie with the movie modal.
Save that movie and return the saved version to the client.
Finally, test with Postman:
Retrieve All the Movies
Add this route to retrieve all the existing movies:
Subsequently, that route finds the movies, sorts them by date in reverse order, and returns them:
Last updated