Run $ npm install
before starting.
Run the file "basics/server1.js" and answer the following questions:
- Identify the endpoint method in the code. Which phase of the event loop will the endpoint be scheduled to run?
- What do you see when you render "http://localhost:3001/" in the browser?
- Try console logging req.body inside the endpoint’s handler? What do you see in the console? Why?
Open the file "basics/server2.js" and answer the following:
- Run the server and list the order in which app.use and app.get functions are executed.
- Move app.use in line 20 to above the app.get endpoint. Run the server and list the order of execution.
- Move all app.use functions above the app.get endpoint. Replace the return in the last app.use with next(). What will be the order of execution?
Open the file "basics/server3.js" and answer the following:
- What are the params in the path?
- Assume the server is running on localhost:3002. Provide a path which would be handled by the endpoint shown and provide the output.
- Construct a URL with inputs for the end point defined in '/user'.
Open the file "basics/breakfastSchema.js". Inspect the schema structure and understand its meaning. Answer the following:
- Run the schema and make sure there are no error.
- What will happen if we create an instance of the schema with eggs set to 13?
- What will happen if we create an instance of the schema with drink set to "Milk"?
- Run "basics/mongoose-demo.js" and see what you get? make the changes in 2 and 3 and run again.
- Define a function insertMany(entries) in the above script, which takes a list of objects {eggs: N, drink: ‘some drink’} and inserts each entry in entries in the MongoDB collection my_db.
We will make a library app to query information about books and create new books.