In this task you will setup your first Express app and create one endpoint that returns a list of all products.
-
Install
nodemon
globally:$ npm install -g nodemon
-
Create a new repository, don't forget to add a
.gitignore
file of typeNode
. Then clone it.
- In your cloned repo, create a
package.json
file usingnpm init -y
. - Create an
app.js
file in your project folder. Don't forget to change the main file inpackage.json
fromindex.js
toapp.js
. - Install
express
and create an express application instance. - Bind your application to port
8000
using thelisten()
method. - Create a script in
package.json
that executesnodemon app.js
when 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.