In this task you will setup your first Express app and create one endpoint that returns a list of all products.
-
Install
nodemonglobally:$ npm install -g nodemon
-
Create a new repository, don't forget to add a
.gitignorefile of typeNode. Then clone it.
- In your cloned repo, create a
package.jsonfile usingnpm init -y. - Create an
app.jsfile in your project folder. Don't forget to change the main file inpackage.jsonfromindex.jstoapp.js. - Install
expressand create an express application instance. - Bind your application to port
8000using thelisten()method. - Create a script in
package.jsonthat executesnodemon app.jswhen you runnpm start.
- Create a new file called
data.js. Copy the following data in this file. Don't forget to export it. - Require it in
app.js.
Create a route that sends the list of your products:
- The route's method should be
get. - The URL for this route should have the following syntax:
/api/products. - The response must be the list of all products.
Test your endpoint using the browser. It should display your array of products.