Create Server Routes
Last updated
Last updated
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 before all the routes, as follows:
Recall that you ran the create
command on the index.js
file earlier. Now perform these tasks:
Bundle two files (index
and db
).
Specify the secrets (env
).
Watch for the changes.
Run this command line for them all:
Grab the URL from the database home:
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:
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: