Before moving on, Scott makes a few code optimizations to demonstrate how to simplify the routing syntax. He also talks briefly about error handling. Node.js doesn’t output any error details by default, so Scott adds an error handler and explains how to use the Node.js debugger/inspector.
(heavy flute music)…- Alright, so before we move on,…I'm just going to make a small optimization…to show you guys.…So now that we have these mini routers…and we could have done this on the app.…But I think it makes more sense to do it here.…In places where we have the same URL.…Like slash id, slash id…slash id.…We have that slash id three times.…Then we have route, route twice.…I can clean this up a little bit…by using the dot router…or the dot route method.…And that exists on an application instance…and a router instance.…
So I can say tiger dot…Oh, sorry,…tigerRouter.route,…that's a function, that just takes in a path,…so in this case, the route.…And then I can say on .get,…just do this.…Do that on .get.…And then now I can just get rid of that.…And then on post, do this.…
And I can get rid of the post.…I'll come out here and then say .post…and put that in there.…I can do the same thing for the other route,…which is id.…So tigerRouter.route.…slash id,…which has got like three of them on it, right?…And then that's got a get,…
This course was created by Frontend Masters. It was originally released on 12/30/2015. We're pleased to host this training in our library.
- Executing Node.js
- Using Express
- What is middleware?
- Testing in Node.js
- Using Mongo with Node.js
- Data modeling
- Querying data with Mongoose
- Identifying sensitive routes
- Configuring the deployment
Skill Level Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building APIs Using Hapi in Node.jswith Kirsten Hunter2h 23m Intermediate
Node.js: Extend and Maintain Applicationswith Daniel Khan3h 35m Intermediate
2. REST APIs
5. Organization and Configuration
7. Data Modeling
10. Securing Routes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.