title
How to Build a RESTful API using Node, Express, and Mongo

description
A REST API is an integral component of a web application. You don't need to be an expert backend developer to make your own. In this workshop, we will walk through the basic building blocks of creating your own REST API using Node.js, Express, and MongoDB. đź”—Slide Deck: https://docs.google.com/presentation/d/1VSlo9JEsoVjNNH4DqOJtSWInKIis5p39lmHvAcLifSw đź”—Github Repo: https://github.com/theoutlander/rest-api-workshop Tutorial from Nick Karnik. Check out his YouTube channel: https://www.youtube.com/channel/UClCm-WAOgN6XLwCpefSVezg Nick on Twitter: https://twitter.com/theoutlander This video was originally a live stream. -- Learn to code for free and get a developer job: https://www.freecodecamp.org Read hundreds of articles on programming: https://medium.freecodecamp.org

detail
{'title': 'How to Build a RESTful API using Node, Express, and Mongo', 'heatmap': [{'end': 1610.458, 'start': 1542.952, 'weight': 1}], 'summary': 'Learn to build a rest api with node express and mongo covering http basics, node.js setup, express routes, mongodb connection, error handling, and deployment using now.sh, emphasizing practical examples and seamless integration with javascript.', 'chapters': [{'end': 61.121, 'segs': [{'end': 61.121, 'src': 'embed', 'start': 1.411, 'weight': 0, 'content': [{'end': 9.041, 'text': 'Hello and welcome to this workshop on building a REST API with Node Express and Mongo.', 'start': 1.411, 'duration': 7.63}, {'end': 12.886, 'text': "Well, let's begin with the agenda for today.", 'start': 10.483, 'duration': 2.403}, {'end': 24.54, 'text': "We're going to start with touching upon some of the concepts related to this topic, followed by the installation of the environment.", 'start': 14.195, 'duration': 10.345}, {'end': 36.125, 'text': 'And we will start with setting up the application before we dive into the crux of this workshop, which is to set up a express web server.', 'start': 25.68, 'duration': 10.445}, {'end': 41.387, 'text': "And then we're going to connect it to MongoDB via Mongoose.", 'start': 36.925, 'duration': 4.462}, {'end': 44.149, 'text': 'And I have a bit of a stretch here.', 'start': 42.728, 'duration': 1.421}, {'end': 51.654, 'text': 'If we have time, I want to show you how to deploy this application using a service called now.sh.', 'start': 44.629, 'duration': 7.025}, {'end': 61.121, 'text': "So let's start with concepts around HTTP, REST, and APIs.", 'start': 55.097, 'duration': 6.024}], 'summary': 'Workshop covers building a rest api with node express and mongo, including setup and deployment.', 'duration': 59.71, 'max_score': 1.411, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1411.jpg'}], 'start': 1.411, 'title': 'Building a rest api with node express', 'summary': 'Covers the process of setting up a rest api with node express and mongo, including concepts, environment installation, setting up the application, connecting to mongodb, and potential deployment using now.sh.', 'chapters': [{'end': 61.121, 'start': 1.411, 'title': 'Building a rest api with node express', 'summary': 'Covers setting up a rest api with node express and mongo, including concepts, environment installation, setting up the application, connecting to mongodb, and potential deployment using now.sh.', 'duration': 59.71, 'highlights': ['Setting up a express web server and connecting it to MongoDB via Mongoose', 'Concepts around HTTP, REST, and APIs', 'Installation of the environment', 'Potential deployment using now.sh']}], 'duration': 59.71, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1411.jpg', 'highlights': ['Setting up a express web server and connecting it to MongoDB via Mongoose', 'Concepts around HTTP, REST, and APIs', 'Potential deployment using now.sh', 'Installation of the environment']}, {'end': 695.955, 'segs': [{'end': 137.07, 'src': 'embed', 'start': 63.903, 'weight': 0, 'content': [{'end': 71.268, 'text': 'So what is HTTP? It stands for Hypertext Transfer Protocol.', 'start': 63.903, 'duration': 7.365}, {'end': 77.342, 'text': 'Now, hypertext is basically text that can link to other text.', 'start': 72.799, 'duration': 4.543}, {'end': 82.345, 'text': "Hence the word hypertext transfer protocol, because that's being transferred.", 'start': 78.483, 'duration': 3.862}, {'end': 86.448, 'text': "It's an application layer protocol.", 'start': 83.946, 'duration': 2.502}, {'end': 91.011, 'text': "It's built on top of the TCP IP protocol.", 'start': 87.709, 'duration': 3.302}, {'end': 99.897, 'text': "What that means is it's using TCP IP for communicating, but then there's application layer logic on top.", 'start': 92.412, 'duration': 7.485}, {'end': 108.545, 'text': 'It pretty much defines all the rules for transferring resources between a client and a server.', 'start': 101.937, 'duration': 6.608}, {'end': 115.673, 'text': 'Now, every HTTP request is executed independently.', 'start': 109.906, 'duration': 5.767}, {'end': 122.201, 'text': 'So on the server side, it does not have knowledge of any of the requests that came before it.', 'start': 116.755, 'duration': 5.446}, {'end': 127.983, 'text': "And that's what makes HTTP stateless.", 'start': 124.56, 'duration': 3.423}, {'end': 131.526, 'text': "But here's an interesting thing.", 'start': 129.464, 'duration': 2.062}, {'end': 137.07, 'text': "It's built on top of TCP IP, which is not stateless.", 'start': 132.186, 'duration': 4.884}], 'summary': 'Http is a stateless application layer protocol built on tcp ip, defining rules for transferring resources between client and server.', 'duration': 73.167, 'max_score': 63.903, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM63903.jpg'}, {'end': 296.211, 'src': 'embed', 'start': 239.377, 'weight': 2, 'content': [{'end': 251.785, 'text': 'Every RESTful resource has a unique ID, which makes it interesting because you can reference different things over the internet via a specific URL.', 'start': 239.377, 'duration': 12.408}, {'end': 259.707, 'text': 'Now client state is not persisted between requests.', 'start': 255.345, 'duration': 4.362}, {'end': 268.249, 'text': "So, uh, that's what rest, uh, basically states that we should be doing.", 'start': 260.927, 'duration': 7.322}, {'end': 278.793, 'text': 'However, that state can be passed along to the server via some attributes that help the server decide how to process that request.', 'start': 269.05, 'duration': 9.743}, {'end': 287.607, 'text': 'REST also states that the application should define a caching policy for responses.', 'start': 280.623, 'duration': 6.984}, {'end': 296.211, 'text': 'What that means is it allows the client to make a decision on the received content,', 'start': 288.447, 'duration': 7.764}], 'summary': 'Restful resources have unique ids; state is passed to server; application defines caching policy.', 'duration': 56.834, 'max_score': 239.377, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM239377.jpg'}, {'end': 378.374, 'src': 'embed', 'start': 351.886, 'weight': 4, 'content': [{'end': 363.352, 'text': 'Basically, you have functions that are defined on the server side and the API tells you what is supported from the server and where the request should be made.', 'start': 351.886, 'duration': 11.466}, {'end': 372.297, 'text': "So essentially, it's going to tell you what the pattern of the URLs are that you're going to use to call into the server.", 'start': 363.833, 'duration': 8.464}, {'end': 378.374, 'text': "Pretty much it's telling you what the format of the request and response is.", 'start': 373.592, 'duration': 4.782}], 'summary': 'Api defines server functions, urls, and request-response format.', 'duration': 26.488, 'max_score': 351.886, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM351886.jpg'}, {'end': 563.65, 'src': 'embed', 'start': 529.392, 'weight': 6, 'content': [{'end': 540.097, 'text': "And then as far as coding today, we're going to use the natively supported ES6 and 7 that's available in Node.", 'start': 529.392, 'duration': 10.705}, {'end': 545.039, 'text': "That way we don't have to set up Babel or any other transpilers.", 'start': 541.237, 'duration': 3.802}, {'end': 556.684, 'text': "If you can go to node.green, you'll notice that it lists out all the features that are supported by node.", 'start': 546.937, 'duration': 9.747}, {'end': 563.65, 'text': 'And this gives you a good idea of which version supports what feature in ES6 and ES7.', 'start': 557.565, 'duration': 6.085}], 'summary': 'Using natively supported es6 and 7 in node to avoid transpilers like babel. node.green lists supported features.', 'duration': 34.258, 'max_score': 529.392, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM529392.jpg'}, {'end': 670.288, 'src': 'embed', 'start': 645.885, 'weight': 5, 'content': [{'end': 652.131, 'text': 'Now I got a question here about if I have any experience with WebStorm and what do I think of it?', 'start': 645.885, 'duration': 6.246}, {'end': 658.957, 'text': "So I've used several IDEs over the years actually 20-some years,", 'start': 653.212, 'duration': 5.745}, {'end': 669.808, 'text': 'and I really love WebStorm because it allows you to do things that most of the other IDEs require you to configure it from scratch, like VS Code,', 'start': 658.957, 'duration': 10.851}, {'end': 670.288, 'text': 'for instance.', 'start': 669.808, 'duration': 0.48}], 'summary': 'Experienced developer praises webstorm for its efficient configuration and usability compared to other ides.', 'duration': 24.403, 'max_score': 645.885, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM645885.jpg'}], 'start': 63.903, 'title': 'Http protocol, rest, and web development tools', 'summary': 'Covers the basics of http, including its role in transferring resources, the concept of rest in http with key principles, and the discussion of apis, rest, and web development tools such as node.js, ides, and rest clients.', 'chapters': [{'end': 163.919, 'start': 63.903, 'title': 'Understanding http protocol', 'summary': 'Explains the basics of http, including its definition, usage of tcp ip, statelessness, and its role in transferring resources between a client and server.', 'duration': 100.016, 'highlights': ['HTTP is an application layer protocol built on top of the TCP IP protocol, defining rules for transferring resources between a client and a server.', 'Every HTTP request is executed independently, making HTTP stateless, despite being built on top of TCP IP, which is not stateless.', 'When an HTTP request is sent, it issues a connection via TCP IP, stays connected to send necessary data, and then disconnects, hence known as stateless.']}, {'end': 324.3, 'start': 166.423, 'title': 'Understanding rest in http', 'summary': 'Explains the concept of rest in http, highlighting its key principles and guidelines, including the use of unique ids for resources, client state management, caching policy for responses, and separation of concerns between clients and servers.', 'duration': 157.877, 'highlights': ['RESTful resource has a unique ID, allowing referencing different things over the internet via a specific URL.', 'Application should define a caching policy for responses, enabling the client to make decisions on received content and improve application performance.', 'Client state is not persisted between requests, but can be passed to the server via attributes to help process requests.', 'HTTP provides a set of methods explicitly used by the REST pattern, with the underlying protocol being HTTP, though REST can be implemented on other protocols.']}, {'end': 695.955, 'start': 324.3, 'title': 'Understanding apis and tools for web development', 'summary': 'Discusses the concept of apis, rest, and the tools required for web development including node.js, ides like vs code, atom, and webstorm, and the use of rest clients like insomnia and postman.', 'duration': 371.655, 'highlights': ['The chapter explains the concept of APIs, including their role in defining functions on the server side and providing guidelines for construction, along with the significance of REST in providing guidelines for API construction.', 'The chapter discusses the tools required for web development, such as IDEs like VS Code, Atom, and WebStorm, the use of Node.js, and the necessity of REST clients like Insomnia and Postman for testing APIs.', 'The chapter emphasizes the importance of using the natively supported ES6 and 7 in Node.js for coding, eliminating the need for transpilers like Babel.', 'The chapter also touches upon the installation requirements for web development, including the need for an IDE, Node.js, NPM, a Mongo database via mlab.com, and a REST client like Insomnia or Postman.']}], 'duration': 632.052, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM63903.jpg', 'highlights': ['HTTP is an application layer protocol defining rules for transferring resources between client and server.', 'HTTP request is executed independently, making HTTP stateless, despite being built on top of TCP IP.', 'RESTful resource has a unique ID, allowing referencing different things over the internet via a specific URL.', 'Application should define a caching policy for responses to improve application performance.', 'The chapter explains the concept of APIs, including their role in defining functions on the server side.', 'The chapter discusses the tools required for web development, such as IDEs like VS Code, Atom, and WebStorm.', 'The chapter emphasizes the importance of using the natively supported ES6 and 7 in Node.js for coding.']}, {'end': 1941.324, 'segs': [{'end': 752.6, 'src': 'embed', 'start': 722.503, 'weight': 0, 'content': [{'end': 729.288, 'text': "And it lends itself very well to Mongo as well because you're storing JavaScript objects or JSON.", 'start': 722.503, 'duration': 6.785}, {'end': 736.933, 'text': "And then what that means is you don't have to go through conversions for your data compared to other databases.", 'start': 730.329, 'duration': 6.604}, {'end': 742.271, 'text': 'Now using MLabs specifically.', 'start': 737.867, 'duration': 4.404}, {'end': 752.6, 'text': 'they have a very good interface and they provide you with a free starter database that you can get, I think, up and running within a minute literally.', 'start': 742.271, 'duration': 10.329}], 'summary': 'Mongodb is efficient for storing javascript objects and json, mlab offers a free starter database that can be set up in under a minute.', 'duration': 30.097, 'max_score': 722.503, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM722503.jpg'}, {'end': 1099.081, 'src': 'embed', 'start': 1064.712, 'weight': 1, 'content': [{'end': 1068.884, 'text': "I'm going to switch back to our presentation window here.", 'start': 1064.712, 'duration': 4.172}, {'end': 1070.512, 'text': 'All right.', 'start': 1068.904, 'duration': 1.608}, {'end': 1072.642, 'text': "So hopefully everyone's caught on to that.", 'start': 1071.094, 'duration': 1.548}, {'end': 1078.712, 'text': "Next, let's get started with Express.", 'start': 1075.791, 'duration': 2.921}, {'end': 1086.956, 'text': 'Express is an NPM package and it is basically a lightweight web server.', 'start': 1080.013, 'duration': 6.943}, {'end': 1099.081, 'text': "What that means is it's taken all the Node.js HTTP classes and added a layer on top of it so that it can communicate,", 'start': 1087.756, 'duration': 11.325}], 'summary': 'Introduction to express, an npm package for lightweight web server.', 'duration': 34.369, 'max_score': 1064.712, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1064712.jpg'}, {'end': 1295.081, 'src': 'embed', 'start': 1254.558, 'weight': 3, 'content': [{'end': 1262.82, 'text': 'So the way you can serve static content in Express is via a function called express.static.', 'start': 1254.558, 'duration': 8.262}, {'end': 1275.179, 'text': "I'm going to tell Express to use this specific static file handler.", 'start': 1266.075, 'duration': 9.104}, {'end': 1279.722, 'text': "This is also known as a middleware and it's built into Express.", 'start': 1275.78, 'duration': 3.942}, {'end': 1295.081, 'text': "So what I can do here is express.static and then I will pass in the name of the folder that I want to serve content from and that's public.", 'start': 1281.983, 'duration': 13.098}], 'summary': "Express serves static content using express.static middleware for folder 'public'.", 'duration': 40.523, 'max_score': 1254.558, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1254558.jpg'}, {'end': 1359.678, 'src': 'embed', 'start': 1327.916, 'weight': 2, 'content': [{'end': 1331.218, 'text': "It's something that's defined on the command line before you start the project.", 'start': 1327.916, 'duration': 3.302}, {'end': 1335.823, 'text': "Or if that's missing, we can substitute 3000 for it.", 'start': 1332.76, 'duration': 3.063}, {'end': 1341.047, 'text': "So I'm going to do process.env, which is environment.port.", 'start': 1336.523, 'duration': 4.524}, {'end': 1347.311, 'text': "And then if that does not exist, we're going to default to 3000.", 'start': 1342.408, 'duration': 4.903}, {'end': 1350.553, 'text': 'So I will substitute this 3000 here with the value port.', 'start': 1347.311, 'duration': 3.242}, {'end': 1359.678, 'text': "And then let's simply output a message that says server.", 'start': 1351.974, 'duration': 7.704}], 'summary': 'Environment port is set to 3000 by default, can be defined on command line.', 'duration': 31.762, 'max_score': 1327.916, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1327916.jpg'}, {'end': 1518.941, 'src': 'embed', 'start': 1492.966, 'weight': 4, 'content': [{'end': 1504.252, 'text': "We're going to create our first API endpoint and API endpoints are usually set up with HTTP verbs.", 'start': 1492.966, 'duration': 11.286}, {'end': 1509.035, 'text': 'So you may have heard about something called a get request.', 'start': 1504.853, 'duration': 4.182}, {'end': 1518.941, 'text': "And what that's essentially doing is making a call to the server as with the get keyword and the servers responding with some content.", 'start': 1509.635, 'duration': 9.306}], 'summary': 'Creating the first api endpoint using http verbs and get request to make a call to the server.', 'duration': 25.975, 'max_score': 1492.966, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1492966.jpg'}, {'end': 1610.458, 'src': 'heatmap', 'start': 1542.952, 'weight': 1, 'content': [{'end': 1547.296, 'text': "And then let's create a file called person.js.", 'start': 1542.952, 'duration': 4.344}, {'end': 1557.519, 'text': "we're going to create what's called a route in Express.", 'start': 1552.657, 'duration': 4.862}, {'end': 1565.782, 'text': 'Basically, you can consider them as mini applications, and there are advantages to it, and I will talk about it in a bit.', 'start': 1559.16, 'duration': 6.622}, {'end': 1586.545, 'text': 'So, essentially, we want to start out by referencing Express here, followed by a router from that Express instance and then,', 'start': 1566.642, 'duration': 19.903}, {'end': 1592.268, 'text': "towards the bottom of the file, we're going to export that router.", 'start': 1586.545, 'duration': 5.723}, {'end': 1600.292, 'text': 'What that allows us to do is now import it in the index.js file.', 'start': 1594.669, 'duration': 5.623}, {'end': 1610.458, 'text': "Now let's go ahead and add, sorry, the route we were talking about earlier.", 'start': 1603.994, 'duration': 6.464}], 'summary': 'Creating a person.js file with a route in express for modular application development.', 'duration': 67.506, 'max_score': 1542.952, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1542952.jpg'}], 'start': 695.955, 'title': 'Node.js, mlab, express, and apis', 'summary': 'Covers the popularity of mlab in the node.js ecosystem, setting up a node.js project, introduction to express as a lightweight web server, configuring express server port, and creating api endpoints using express, emphasizing its seamless integration with javascript and capability to communicate via restful endpoints.', 'chapters': [{'end': 780.699, 'start': 695.955, 'title': 'Popular use of mlab in node', 'summary': 'Discusses the popularity of mlab in the node.js ecosystem, attributing it to the seamless integration with javascript, the lack of data conversion, and the user-friendly interface that allows quick setup of a free starter database.', 'duration': 84.744, 'highlights': ['Mongo is integral to most Node applications due to coding in JavaScript, allowing easy storage of JavaScript objects or JSON without data conversions.', "MLab's popularity is due to its user-friendly interface and provision of a free starter database, allowing setup within a minute."]}, {'end': 1064.692, 'start': 781.4, 'title': 'Setting up node.js project', 'summary': 'Covers setting up a node.js project, including creating folders, initializing project, creating scripts, running the application, and modifying the package.json file, with a focus on creating a simple hello world script and setting up a start command using npm.', 'duration': 283.292, 'highlights': ['Creating a folder under the root and call it src, which stands for source. The process involves creating a source folder under the root directory of the project.', 'Initializing the project with npm init and providing the optional parameter dash y to generate the package JSON file without asking questions. The speaker explains the process of initializing the project using npm init and specifying an optional parameter to generate the package JSON file without user input.', 'Setting up a start command in the package.json file to run the application without having to manually point to the file and type in node. The process involves modifying the scripts section of the package.json file to add a start command, allowing the application to be run without manual input of the file path and command.']}, {'end': 1295.081, 'start': 1064.712, 'title': 'Introduction to express web server', 'summary': 'Introduces express as a lightweight web server using npm package, explains the process of installing and referencing the library, creating a basic express application, and serving static content, emphasizing its capability to communicate via restful endpoints and its integration with node.js http classes.', 'duration': 230.369, 'highlights': ['Express is a lightweight web server that allows you to communicate via RESTful endpoints, integrating with Node.js HTTP classes.', "Installing Express dependency involves using 'npm install express', which automatically saves it to the package.json file.", "Referencing the express library and creating an application involves using 'let express = require express' and 'app = express()', respectively.", "Serving static content in Express is achieved through a middleware called 'express.static', facilitating the storage and delivery of resources like HTML files, images, JavaScript, and CSS."]}, {'end': 1433.74, 'start': 1295.121, 'title': 'Configuring express server port', 'summary': "Explains how to configure the express server to listen on a specific port, reading the port value from an environment variable and defaulting to 3000 if not defined, while also displaying a message indicating the server's status and port.", 'duration': 138.619, 'highlights': ['Express server is configured to listen on a specific port, obtained from an environment variable or defaulting to 3000 if not defined.', "A message is displayed indicating the server's status and the port it is running on, promoting server awareness and facilitating debugging.", "The program is shown to keep running until manually stopped, emphasizing the server's persistent operation."]}, {'end': 1941.324, 'start': 1433.74, 'title': 'Creating api endpoint with express', 'summary': 'Discusses serving static content through express, creating the first api endpoint using http verbs, and comparing the use of insomnia and postman for testing apis.', 'duration': 507.584, 'highlights': ['The chapter discusses serving static content through Express The speaker explains how to serve static content through Express by creating a public folder and configuring Express to serve that static content.', "Creating the first API endpoint using HTTP verbs The speaker introduces the concept of API endpoints and demonstrates the creation of a 'get' request to retrieve a person object, providing a simple route and explaining the callback method for handling the request and response.", 'Comparison of Insomnia and Postman for testing APIs The speaker compares Insomnia and Postman, expressing a preference for Insomnia due to its ease of use and intuitive interface, while acknowledging the advanced features of Postman.']}], 'duration': 1245.369, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM695955.jpg', 'highlights': ["MLab's popularity is due to its user-friendly interface and provision of a free starter database, allowing setup within a minute.", 'Express is a lightweight web server that allows you to communicate via RESTful endpoints, integrating with Node.js HTTP classes.', 'Express server is configured to listen on a specific port, obtained from an environment variable or defaulting to 3000 if not defined.', "Serving static content in Express is achieved through a middleware called 'express.static', facilitating the storage and delivery of resources like HTML files, images, JavaScript, and CSS.", "Creating the first API endpoint using HTTP verbs The speaker introduces the concept of API endpoints and demonstrates the creation of a 'get' request to retrieve a person object, providing a simple route and explaining the callback method for handling the request and response."]}, {'end': 3375.05, 'segs': [{'end': 1970.311, 'src': 'embed', 'start': 1941.824, 'weight': 0, 'content': [{'end': 1946.848, 'text': "Sometimes I find it a bit too bloated, but They're both very similar.", 'start': 1941.824, 'duration': 5.024}, {'end': 1948.89, 'text': 'So in this case,', 'start': 1947.549, 'duration': 1.341}, {'end': 1963.245, 'text': 'I think what GetPerson allows us to do here in Insomnia is also generate some code that we can then test out through Node or any other projects.', 'start': 1948.89, 'duration': 14.355}, {'end': 1964.447, 'text': "I'm going to click on that real quick.", 'start': 1963.305, 'duration': 1.142}, {'end': 1967.889, 'text': 'And then notice that it has a bunch of languages here.', 'start': 1965.147, 'duration': 2.742}, {'end': 1970.311, 'text': 'And so essentially you can pick something.', 'start': 1968.65, 'duration': 1.661}], 'summary': 'Getperson in insomnia generates code for testing in multiple languages.', 'duration': 28.487, 'max_score': 1941.824, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1941824.jpg'}, {'end': 2118.269, 'src': 'embed', 'start': 2081.245, 'weight': 1, 'content': [{'end': 2091.774, 'text': "So basically, if you were to deploy this through a CI system like CircleCI, it's going to do npm install when it downloads the project.", 'start': 2081.245, 'duration': 10.529}, {'end': 2096.438, 'text': 'And all that is going to do is install dev dependencies.', 'start': 2092.353, 'duration': 4.085}, {'end': 2104.104, 'text': 'All right, so we have nodemon created here.', 'start': 2101.982, 'duration': 2.122}, {'end': 2111.247, 'text': "What we're going to do is learn how to use it, actually.", 'start': 2107.185, 'duration': 4.062}, {'end': 2114.628, 'text': "Let's just put it in a, let's create a command here.", 'start': 2111.567, 'duration': 3.061}, {'end': 2118.269, 'text': "So we're going to call it start watch.", 'start': 2114.648, 'duration': 3.621}], 'summary': "Deploying through ci system like circleci runs 'npm install' to install dev dependencies and uses nodemon to start watch.", 'duration': 37.024, 'max_score': 2081.245, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM2081245.jpg'}, {'end': 2246.985, 'src': 'embed', 'start': 2207.624, 'weight': 2, 'content': [{'end': 2224.509, 'text': "And one of the things that we want to be able to do is Let's say pass in an additional sort of sub route that can be mapped to a variable.", 'start': 2207.624, 'duration': 16.885}, {'end': 2229.734, 'text': "So let's call it name and we need to specify a colon before it.", 'start': 2225.07, 'duration': 4.664}, {'end': 2234.698, 'text': 'So Express knows that it needs to map that to a variable.', 'start': 2230.154, 'duration': 4.544}, {'end': 2243.185, 'text': 'And these variables here are available through the request object in a property called params.', 'start': 2235.759, 'duration': 7.426}, {'end': 2246.985, 'text': "So let's just print that out here.", 'start': 2244.781, 'duration': 2.204}], 'summary': "Express allows mapping sub routes to variables, accessible through the request object's params property.", 'duration': 39.361, 'max_score': 2207.624, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM2207624.jpg'}, {'end': 2589.629, 'src': 'embed', 'start': 2557.14, 'weight': 3, 'content': [{'end': 2565.124, 'text': 'Now middleware are simply functions that are executed back to back or serially in the request pipeline.', 'start': 2557.14, 'duration': 7.984}, {'end': 2570.446, 'text': 'So when a request comes in, there are a bunch of functions.', 'start': 2566.184, 'duration': 4.262}, {'end': 2576.092, 'text': 'Think of it as an array of functions and they execute from the index zero all the way to the end.', 'start': 2571.286, 'duration': 4.806}, {'end': 2579.597, 'text': "And each one calls, when it's done, calls into the next function.", 'start': 2576.593, 'duration': 3.004}, {'end': 2589.629, 'text': 'It has the ability to also modify the request and response objects.', 'start': 2582.02, 'duration': 7.609}], 'summary': 'Middleware functions execute serially in the request pipeline, modifying request and response objects.', 'duration': 32.489, 'max_score': 2557.14, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM2557140.jpg'}, {'end': 2890.489, 'src': 'embed', 'start': 2860.396, 'weight': 4, 'content': [{'end': 2871.36, 'text': 'So another thing we can do with these middleware is handle 404 and 500 errors and other errors and things like that.', 'start': 2860.396, 'duration': 10.964}, {'end': 2874.041, 'text': "And so let's go through how that's done.", 'start': 2872.14, 'duration': 1.901}, {'end': 2887.366, 'text': "We're going to respond back for 404, let's say with some content initially a string and then I can also show you how to respond with a specific file.", 'start': 2875.502, 'duration': 11.864}, {'end': 2890.489, 'text': 'All right.', 'start': 2890.049, 'duration': 0.44}], 'summary': 'Middleware can handle 404 and 500 errors, and respond with content or files.', 'duration': 30.093, 'max_score': 2860.396, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM2860396.jpg'}], 'start': 1941.824, 'title': "Insomnia's getperson feature, nodemon setup, express routes, middleware, and error handling", 'summary': "Covers insomnia's getperson feature for testing, setting up nodemon for monitoring changes, creating express routes and handling parameters, implementing middleware for logging and error handling, and serving custom error responses, with examples and benefits explained.", 'chapters': [{'end': 1992.07, 'start': 1941.824, 'title': "Insomnia's getperson feature", 'summary': "Explains how insomnia's getperson feature allows users to generate code for testing through node or other projects, with options to select different languages and libraries for making requests.", 'duration': 50.246, 'highlights': ["Insomnia's GetPerson feature allows generating code for testing through Node or other projects, with options to select different languages and libraries for making requests.", "The option of choosing different languages and libraries for making requests is available in Insomnia's GetPerson feature.", 'Choosing request as the library for making requests in Node.js is recommended due to its conciseness.']}, {'end': 2186.02, 'start': 1992.25, 'title': 'Setting up nodemon for monitoring changes', 'summary': 'Discusses setting up nodemon to monitor changes in a development environment, including installing nodemon as a dev dependency using npm, specifying folders to be monitored, and the benefits of using dev dependencies for development time only.', 'duration': 193.77, 'highlights': ['Nodemon is installed as a dev dependency using npm, which allows for monitoring changes in a development environment.', "Prior to npm5, specifying 'save' was required to save nodemon as a dependency in package.json, but with the latest npm version, this step is no longer necessary.", 'The use of dev dependencies ensures that nodemon is only available during development time, simplifying deployment through CI systems like CircleCI.', "The 'npm run' command is utilized to run nodemon and monitor specific files or folders for changes.", 'Nodemon internally runs the startup file and monitors a set of folders, providing flexibility for customization based on documentation and familiarity with various libraries.']}, {'end': 2520.671, 'start': 2186.281, 'title': 'Express routes and parameters', 'summary': 'Covers creating routes and handling parameters in an express application, allowing users to pass in variables and query strings to access and manipulate data, demonstrating three ways to accomplish this.', 'duration': 334.39, 'highlights': ['Creating routes and handling parameters The chapter explains creating routes and handling parameters in an Express application, demonstrating how to allow users to pass in variables and query strings to access and manipulate data.', 'Demonstrating three ways to accomplish this The chapter demonstrates three different methods to accomplish handling parameters in an Express application, showcasing the flexibility and options available to developers.', 'Accessing and manipulating data through parameters and query strings The chapter illustrates how users can access and manipulate data by passing variables and query strings, enhancing the understanding of handling dynamic data in an Express application.']}, {'end': 2978.492, 'start': 2520.971, 'title': 'Express middleware and error handling', 'summary': 'Explains the concept of middleware in express, illustrating how they are executed in the request pipeline and demonstrating the setup of a logging middleware to capture incoming requests. it also covers handling 404 errors by adding a middleware function to respond with a custom message and status code.', 'duration': 457.521, 'highlights': ['Middleware in Express are functions executed in the request pipeline, allowing modification of request and response objects and the ability to pass additional details downstream or to respond and not call into other functions downstream. Middleware in Express are executed in the request pipeline, providing the ability to modify request and response objects and pass additional details downstream. They can also choose to respond and not call into other functions downstream.', 'Demonstrated setting up a logging middleware to capture incoming requests, using app.use to add the middleware function and ensuring the correct order of handlers to capture every request as the first thing in the pipeline. The chapter demonstrates setting up a logging middleware to capture incoming requests, using app.use to add the middleware function and emphasizing the importance of the order of handlers to capture every request as the first thing in the pipeline.', 'Explained the process of handling 404 errors by adding a middleware function towards the end of the chain to respond with a custom message and status code, providing a demonstration of responding with a 404 status code and a custom message for a resource not found. The chapter explains the process of handling 404 errors by adding a middleware function towards the end of the chain to respond with a custom message and status code. It provides a demonstration of responding with a 404 status code and a custom message for a resource not found.']}, {'end': 3375.05, 'start': 2980.663, 'title': 'Handling errors in express', 'summary': 'Discusses handling 404 and 500 errors in express, including adding separate handlers for each, and serving a custom 500.html file as a response, along with creating a route to generate an error and trigger the 500 error handler.', 'duration': 394.387, 'highlights': ['Handling 404 and 500 errors in Express, including adding separate handlers for each, and serving a custom 500.html file as a response.', 'Creating a route to generate an error and trigger the 500 error handler.', "Discussing the preference of using the IDE's terminal versus a separate terminal app based on comfort and efficiency, with no significant difference in speed mentioned."]}], 'duration': 1433.226, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM1941824.jpg', 'highlights': ["Insomnia's GetPerson feature allows generating code for testing through Node or other projects, with options to select different languages and libraries for making requests.", 'Nodemon is installed as a dev dependency using npm, which allows for monitoring changes in a development environment.', 'Creating routes and handling parameters in an Express application, demonstrating how to allow users to pass in variables and query strings to access and manipulate data.', 'Middleware in Express are functions executed in the request pipeline, allowing modification of request and response objects and the ability to pass additional details downstream or to respond and not call into other functions downstream.', 'Handling 404 and 500 errors in Express, including adding separate handlers for each, and serving a custom 500.html file as a response.']}, {'end': 4249.796, 'segs': [{'end': 3495.665, 'src': 'embed', 'start': 3441.38, 'weight': 1, 'content': [{'end': 3449.721, 'text': 'because you can store json documents directly without having to define relationships between tables and things like that.', 'start': 3441.38, 'duration': 8.341}, {'end': 3459.283, 'text': "so there are pros and cons to it, but i've been able to build most applications without sql databases in the past few years,", 'start': 3449.721, 'duration': 9.562}, {'end': 3463.686, 'text': "mainly because you're able to scale your application in many ways.", 'start': 3459.283, 'duration': 4.403}, {'end': 3471.132, 'text': 'It may not be the most efficient database out there, but it certainly simplifies your development process significantly.', 'start': 3464.446, 'duration': 6.686}, {'end': 3475.416, 'text': "Anyway, so let's get Mongoose connected.", 'start': 3472.574, 'duration': 2.842}, {'end': 3480.16, 'text': "We're going to do something similar to what we did with Express.", 'start': 3475.816, 'duration': 4.344}, {'end': 3483.843, 'text': "So we're going to install the dependency and we're going to reference it.", 'start': 3480.42, 'duration': 3.423}, {'end': 3487.767, 'text': "And then we're going to focus on creating a CRUD API.", 'start': 3484.544, 'duration': 3.223}, {'end': 3495.665, 'text': 'So, essentially,', 'start': 3491.863, 'duration': 3.802}], 'summary': 'Storing json documents allows for scalable applications without sql, simplifying development significantly.', 'duration': 54.285, 'max_score': 3441.38, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM3441380.jpg'}, {'end': 3779.099, 'src': 'embed', 'start': 3747.836, 'weight': 0, 'content': [{'end': 3753.04, 'text': 'And it provides you with additional methods that you can use to make database queries and things like that.', 'start': 3747.836, 'duration': 5.204}, {'end': 3756.563, 'text': "So let's define a customer schema next.", 'start': 3754.081, 'duration': 2.482}, {'end': 3764.535, 'text': 'And the way you do that is by creating a new instance of mongoose.schema.', 'start': 3758.493, 'duration': 6.042}, {'end': 3772.357, 'text': 'And let me, sorry, if you were not able to read this, there you go.', 'start': 3767.256, 'duration': 5.101}, {'end': 3779.099, 'text': "So within the customer schema that we're defining, let's create a couple of attributes there.", 'start': 3772.377, 'duration': 6.722}], 'summary': 'Introduction to additional methods for database queries and creating a customer schema using mongoose.schema.', 'duration': 31.263, 'max_score': 3747.836, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM3747836.jpg'}, {'end': 3898.847, 'src': 'embed', 'start': 3867.644, 'weight': 3, 'content': [{'end': 3870.729, 'text': "Okay So let's do a quick recap here.", 'start': 3867.644, 'duration': 3.085}, {'end': 3872.831, 'text': 'We referenced Mongoose.', 'start': 3871.75, 'duration': 1.081}, {'end': 3880.437, 'text': 'I defined some attributes, some variables here that help us construct the database connection string.', 'start': 3873.511, 'duration': 6.926}, {'end': 3883.159, 'text': "And then we're connecting to the database.", 'start': 3881.658, 'duration': 1.501}, {'end': 3888.419, 'text': "And we're defining a customer schema.", 'start': 3884.836, 'duration': 3.583}, {'end': 3898.847, 'text': 'We have two attributes in there name, which is a simple string, and the email attribute has additional properties on it, which, sorry,', 'start': 3888.999, 'duration': 9.848}], 'summary': 'Recap: mongoose referenced, attributes defined, database connected, customer schema defined.', 'duration': 31.203, 'max_score': 3867.644, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM3867644.jpg'}, {'end': 4028.607, 'src': 'embed', 'start': 3982.746, 'weight': 4, 'content': [{'end': 3995.108, 'text': 'Oops And then we want to reference, create the router instance from that express reference.', 'start': 3982.746, 'duration': 12.362}, {'end': 3996.449, 'text': 'All right.', 'start': 3996.169, 'duration': 0.28}, {'end': 4006.117, 'text': "So let's, let's create a route that will allow us to create a new customer.", 'start': 3997.55, 'duration': 8.567}, {'end': 4015.225, 'text': "So here we'll create a new customer and we're going to create what's called a post method.", 'start': 4006.998, 'duration': 8.227}, {'end': 4028.607, 'text': "And notice that the type of operation you're trying to define, the verb itself, is available as a method in Express.", 'start': 4016.935, 'duration': 11.672}], 'summary': 'Creating a new customer route using a post method in express.', 'duration': 45.861, 'max_score': 3982.746, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM3982746.jpg'}], 'start': 3378.243, 'title': 'Mongodb with mongoose and express routes', 'summary': 'Covers connecting to mongodb with mongoose, creating a crud api, defining a customer schema, setting up mongoose model for customer schema with validation, creating express routes for crud operations, and using the body-parser module for handling json data in the request body.', 'chapters': [{'end': 3801.757, 'start': 3378.243, 'title': 'Connecting to mongodb with mongoose', 'summary': 'Covers the process of connecting to mongodb using mongoose, discussing its advantages, the creation of a crud api, and the definition of a customer schema, emphasizing the simplicity and efficiency of using mongodb for application development.', 'duration': 423.514, 'highlights': ['Advantages of MongoDB over SQL databases MongoDB simplifies the development process significantly, allowing the direct storage of JSON documents without defining relationships between tables, enabling the scaling of applications in multiple ways.', 'Connecting Mongoose to MongoDB The process involves installing the dependency, referencing it, and creating a model in Mongoose to perform CRUD operations via RESTful endpoints, streamlining the connection to the database and the development process.', 'Definition of customer schema with Mongoose The creation of a customer schema in Mongoose involves defining attributes such as name and email, showcasing the versatility of Mongoose for constructing models in MongoDB.']}, {'end': 4249.796, 'start': 3801.777, 'title': 'Setting up mongoose model and express routes', 'summary': 'Explains the process of setting up a mongoose model for a customer schema with attributes and validation, and creating an express route for handling crud operations, including the installation and use of the body-parser module to handle json data in the request body.', 'duration': 448.019, 'highlights': ['The chapter explains the process of setting up a Mongoose model for a customer schema with attributes and validation It describes defining a customer schema with name and email attributes, specifying the type, required property, and uniqueness, and exporting it as a Mongoose model.', 'Creating an Express route for handling CRUD operations, including the installation and use of the body-parser module to handle JSON data in the request body It includes creating a route to allow creating a new customer, using the post method, and installing the body-parser module to handle incoming JSON data in the request body.']}], 'duration': 871.553, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM3378243.jpg', 'highlights': ['Covers connecting to mongodb with mongoose, creating a crud api, defining a customer schema, setting up mongoose model for customer schema with validation, creating express routes for crud operations, and using the body-parser module for handling json data in the request body.', 'Advantages of MongoDB over SQL databases MongoDB simplifies the development process significantly, allowing the direct storage of JSON documents without defining relationships between tables, enabling the scaling of applications in multiple ways.', 'Connecting Mongoose to MongoDB The process involves installing the dependency, referencing it, and creating a model in Mongoose to perform CRUD operations via RESTful endpoints, streamlining the connection to the database and the development process.', 'The chapter explains the process of setting up a Mongoose model for a customer schema with attributes and validation It describes defining a customer schema with name and email attributes, specifying the type, required property, and uniqueness, and exporting it as a Mongoose model.', 'Creating an Express route for handling CRUD operations, including the installation and use of the body-parser module to handle JSON data in the request body It includes creating a route to allow creating a new customer, using the post method, and installing the body-parser module to handle incoming JSON data in the request body.', 'Definition of customer schema with Mongoose The creation of a customer schema in Mongoose involves defining attributes such as name and email, showcasing the versatility of Mongoose for constructing models in MongoDB.']}, {'end': 4626.593, 'segs': [{'end': 4283.652, 'src': 'embed', 'start': 4250.637, 'weight': 0, 'content': [{'end': 4256.802, 'text': 'And essentially, if it does not exist, we want to return a response.', 'start': 4250.637, 'duration': 6.165}, {'end': 4269.526, 'text': "with a status code of 400, which means it's a bad request, and send a string with that response.", 'start': 4258.242, 'duration': 11.284}, {'end': 4274.427, 'text': "And let's say we tell it that request body is missing.", 'start': 4269.846, 'duration': 4.581}, {'end': 4275.187, 'text': 'So the..', 'start': 4274.847, 'duration': 0.34}, {'end': 4281.531, 'text': "recipient, the caller sort of knows what's wrong exactly here.", 'start': 4277.768, 'duration': 3.763}, {'end': 4283.652, 'text': 'in terms of these status messages,', 'start': 4281.531, 'duration': 2.121}], 'summary': 'Return a response with status code 400 for missing request body.', 'duration': 33.015, 'max_score': 4250.637, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4250637.jpg'}, {'end': 4351.521, 'src': 'embed', 'start': 4312.481, 'weight': 2, 'content': [{'end': 4320.071, 'text': "So let's do that here with referencing the customer model.", 'start': 4312.481, 'duration': 7.59}, {'end': 4324.024, 'text': 'And request.', 'start': 4322.663, 'duration': 1.361}, {'end': 4331.048, 'text': "So we're going to pass in whatever was part of the request body and construct that model there.", 'start': 4324.304, 'duration': 6.744}, {'end': 4337.672, 'text': "Essentially, what we're going to pass here is something like this.", 'start': 4332.429, 'duration': 5.243}, {'end': 4343.316, 'text': "Let's say user equal to, we need a name.", 'start': 4339.393, 'duration': 3.923}, {'end': 4347.338, 'text': 'So this is first name, last name, whatever.', 'start': 4344.557, 'duration': 2.781}, {'end': 4351.521, 'text': 'And then email, email at gmail.com.', 'start': 4347.538, 'duration': 3.983}], 'summary': 'Referencing the customer model, constructing the model with user details like first name, last name, and email.', 'duration': 39.04, 'max_score': 4312.481, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4312481.jpg'}, {'end': 4462.244, 'src': 'embed', 'start': 4380.404, 'weight': 1, 'content': [{'end': 4391.332, 'text': 'the the the request.body object and validate it via the customer model and save it to the database.', 'start': 4380.404, 'duration': 10.928}, {'end': 4399.943, 'text': "so we're going to use promises here to sort of follow up on this request.", 'start': 4391.332, 'duration': 8.611}, {'end': 4402.784, 'text': "So after we save, we're going to call then.", 'start': 4400.183, 'duration': 2.601}, {'end': 4408.527, 'text': 'And then is going to, I believe, respond with the document that it saved.', 'start': 4403.705, 'duration': 4.822}, {'end': 4424.934, 'text': "And so what we're going to do is if we weren't able to save the document or it's an array of documents, I believe, or if document.length is zero,", 'start': 4409.727, 'duration': 15.207}, {'end': 4428.526, 'text': 'then we want to respond with an error.', 'start': 4426.365, 'duration': 2.161}, {'end': 4438.793, 'text': "So let's say it's an internal server error, and we're going to send that document, which should be null in this case or an empty array.", 'start': 4430.447, 'duration': 8.346}, {'end': 4450.56, 'text': "And if that's not the case, then we want to respond with a status code of 201, which stands for resource was created.", 'start': 4440.413, 'duration': 10.147}, {'end': 4453.601, 'text': 'Now, this is sort of optional in a way.', 'start': 4451.52, 'duration': 2.081}, {'end': 4454.962, 'text': 'You could have responded with 200 as well.', 'start': 4453.722, 'duration': 1.24}, {'end': 4462.244, 'text': "But that's where sort of REST sort of defines the guidelines, you know, for how things should be constructed.", 'start': 4456.323, 'duration': 5.921}], 'summary': 'Using promises to save and respond with status codes based on document validation', 'duration': 81.84, 'max_score': 4380.404, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4380404.jpg'}, {'end': 4522.109, 'src': 'embed', 'start': 4489.659, 'weight': 5, 'content': [{'end': 4493.5, 'text': 'And so if there were any errors, those will be caught here.', 'start': 4489.659, 'duration': 3.841}, {'end': 4497.781, 'text': "And so we'll sort of do the same thing as above, respond with an error code there.", 'start': 4493.6, 'duration': 4.181}, {'end': 4507.724, 'text': "And then instead of send, we're going to call JSON, which is going to take in the error object and transform it and send it over.", 'start': 4498.402, 'duration': 9.322}, {'end': 4509.865, 'text': 'instead of a specific message.', 'start': 4508.404, 'duration': 1.461}, {'end': 4511.705, 'text': 'this kind of gives us more details.', 'start': 4509.865, 'duration': 1.84}, {'end': 4514.026, 'text': "now it's up to you how you want to respond.", 'start': 4511.705, 'duration': 2.321}, {'end': 4522.109, 'text': 'you know in your projects and stuff, all right, so that should complete the customer creation process.', 'start': 4514.026, 'duration': 8.083}], 'summary': 'Error handling and response transformation implemented for customer creation process.', 'duration': 32.45, 'max_score': 4489.659, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4489659.jpg'}, {'end': 4626.593, 'src': 'embed', 'start': 4603.739, 'weight': 6, 'content': [{'end': 4613.483, 'text': 'Essentially, you could mess things up by having an incorrect order where something might be returning earlier than you expect it to.', 'start': 4603.739, 'duration': 9.744}, {'end': 4621.11, 'text': "Anyway, so I've used, I think this, so sometimes NodeMon will crash and it may not restart.", 'start': 4615.006, 'duration': 6.104}, {'end': 4626.593, 'text': 'So at that point, what you can do is in your console, you can type in RS, which tells it to restart.', 'start': 4621.51, 'duration': 5.083}], 'summary': 'Using rs in console restarts nodemon after crashes.', 'duration': 22.854, 'max_score': 4603.739, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4603739.jpg'}], 'start': 4250.637, 'title': 'Request handling and restful api error handling', 'summary': 'Covers handling request body in a web application, specifying status codes for different scenarios, and saving customer model data to the database; as well as error handling in a restful api, including responding with error codes for null or empty documents, defining response codes for resource creation, catching and responding to exceptions, and ensuring proper routing in node.js.', 'chapters': [{'end': 4408.527, 'start': 4250.637, 'title': 'Handling request body and saving customer model', 'summary': 'Discusses handling the request body in a web application, specifying status codes for different scenarios, and saving customer model data to the database using promises.', 'duration': 157.89, 'highlights': ['Handling request body and specifying status codes The chapter emphasizes returning a response with a status code of 400 and a corresponding string when the request body is missing, and recommends using an existing package like http status for defining status codes.', 'Creating and saving customer model data to the database The process of creating an instance of the customer model using the request body and saving it to the database is explained, along with the use of promises to handle the request and the response from the database.', "Constructing the customer model with request body data The construction of the customer model using the data from the request body, including the user's name and email, is detailed as part of the process of saving the model to the database."]}, {'end': 4626.593, 'start': 4409.727, 'title': 'Restful api error handling', 'summary': 'Discusses error handling in a restful api, including responding with error codes for null or empty documents, defining response codes for resource creation, catching and responding to exceptions, and ensuring proper routing in node.js.', 'duration': 216.866, 'highlights': ['Respond with an error if the document is null or an empty array, indicating an internal server error.', 'Define response codes for resource creation, such as 201 for success, as per REST guidelines.', 'Catch and respond to exceptions by sending appropriate error codes and using JSON to provide detailed error information.', "Ensure proper routing in Node.js to avoid unexpected returns or crashes, and use 'RS' command to manually restart NodeMon if needed."]}], 'duration': 375.956, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4250637.jpg', 'highlights': ['Handling request body and specifying status codes: Emphasize returning a response with a status code of 400 and a corresponding string when the request body is missing.', 'Creating and saving customer model data to the database: Explain the process of creating an instance of the customer model using the request body and saving it to the database, along with the use of promises to handle the request and the response from the database.', "Constructing the customer model with request body data: Detail the construction of the customer model using the data from the request body, including the user's name and email, as part of the process of saving the model to the database.", 'Respond with an error if the document is null or an empty array, indicating an internal server error.', 'Define response codes for resource creation, such as 201 for success, as per REST guidelines.', 'Catch and respond to exceptions by sending appropriate error codes and using JSON to provide detailed error information.', "Ensure proper routing in Node.js to avoid unexpected returns or crashes, and use 'RS' command to manually restart NodeMon if needed."]}, {'end': 5500.752, 'segs': [{'end': 4659.708, 'src': 'embed', 'start': 4627.954, 'weight': 1, 'content': [{'end': 4638.998, 'text': "And what's happening over here? Line 16, it does not like this because I think I missed something here in customer.js.", 'start': 4627.954, 'duration': 11.044}, {'end': 4646.08, 'text': "Yep So we're not, I believe we're not exporting that router.", 'start': 4640.139, 'duration': 5.941}, {'end': 4648.461, 'text': "So that's what we want to do here.", 'start': 4647.101, 'duration': 1.36}, {'end': 4653.463, 'text': 'So module.exports equals router.', 'start': 4649.101, 'duration': 4.362}, {'end': 4654.223, 'text': 'There you go.', 'start': 4653.863, 'duration': 0.36}, {'end': 4658.166, 'text': "Now it's going to, okay, so server started now.", 'start': 4655.202, 'duration': 2.964}, {'end': 4659.708, 'text': 'So a couple of things we had missed.', 'start': 4658.426, 'duration': 1.282}], 'summary': 'Debugging and fixing missing export in customer.js on line 16.', 'duration': 31.754, 'max_score': 4627.954, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4627954.jpg'}, {'end': 4946.549, 'src': 'embed', 'start': 4914.608, 'weight': 3, 'content': [{'end': 4917.09, 'text': 'But I would encourage you to look at their documentation.', 'start': 4914.608, 'duration': 2.482}, {'end': 4921.611, 'text': 'There are also lots of interesting articles out there that will highlight some of those.', 'start': 4918.27, 'duration': 3.341}, {'end': 4924.633, 'text': "But anyway, in this case, we're going to use findOne.", 'start': 4922.912, 'duration': 1.721}, {'end': 4930.291, 'text': 'And findOne takes an object with attributes as the query parameter.', 'start': 4925.686, 'duration': 4.605}, {'end': 4938.28, 'text': "So in this case, we're going to pass in the email, which we're expecting via query.email, for instance.", 'start': 4930.952, 'duration': 7.328}, {'end': 4941.383, 'text': 'And then of course, we want to make sure that it exists up here.', 'start': 4938.9, 'duration': 2.483}, {'end': 4946.549, 'text': "So we're going to check for request.query.email if that's not present.", 'start': 4941.623, 'duration': 4.926}], 'summary': 'Encourages using findone with object attributes as query parameter, checking for the presence of request.query.email.', 'duration': 31.941, 'max_score': 4914.608, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4914608.jpg'}, {'end': 5375.939, 'src': 'embed', 'start': 5348.723, 'weight': 0, 'content': [{'end': 5354.991, 'text': 'We created a customer model, which is part of the customer model.js file.', 'start': 5348.723, 'duration': 6.268}, {'end': 5357.194, 'text': "You're familiar with this by now.", 'start': 5355.813, 'duration': 1.381}, {'end': 5360.336, 'text': 'And so we reference that in Customer.js.', 'start': 5358.436, 'duration': 1.9}, {'end': 5361.096, 'text': "That's our route.", 'start': 5360.436, 'duration': 0.66}, {'end': 5363.577, 'text': "And essentially, we're creating a route here.", 'start': 5361.957, 'duration': 1.62}, {'end': 5373.099, 'text': "The first piece is a create operation that's handled via the post verb, and it's calling into Customer.", 'start': 5364.157, 'duration': 8.942}, {'end': 5375.939, 'text': "We're expecting a body to be passed in.", 'start': 5373.819, 'duration': 2.12}], 'summary': 'Created a customer model.js file with a create route and post verb.', 'duration': 27.216, 'max_score': 5348.723, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5348723.jpg'}, {'end': 5475.249, 'src': 'embed', 'start': 5424.98, 'weight': 2, 'content': [{'end': 5430.663, 'text': "And so we're handling, you know, different error conditions and whatnot here.", 'start': 5424.98, 'duration': 5.683}, {'end': 5432.904, 'text': 'So this is pretty straightforward here.', 'start': 5431.263, 'duration': 1.641}, {'end': 5438.328, 'text': 'I think the important piece is how to create that route and how to respond.', 'start': 5433.164, 'duration': 5.164}, {'end': 5445.036, 'text': "You want to make sure you're passing back the right error codes and things like that, or status codes and things like that.", 'start': 5439.47, 'duration': 5.566}, {'end': 5448.145, 'text': 'Get request was very similar.', 'start': 5446.664, 'duration': 1.481}, {'end': 5452.167, 'text': 'You know, you change the verb here, the method name that maps to get.', 'start': 5448.165, 'duration': 4.002}, {'end': 5457.59, 'text': 'Similar things here, just the method on your customer model changes.', 'start': 5453.988, 'duration': 3.602}, {'end': 5464.794, 'text': 'So essentially that was like the only big change between all the other methods on the route.', 'start': 5458.531, 'duration': 6.263}, {'end': 5468.136, 'text': 'So you have get and on update you have find one update.', 'start': 5465.514, 'duration': 2.622}, {'end': 5471.587, 'text': 'And for delete, you have find one and remove.', 'start': 5469.426, 'duration': 2.161}, {'end': 5475.249, 'text': 'So I think that that about wraps this up.', 'start': 5472.648, 'duration': 2.601}], 'summary': 'Handling error conditions, creating routes, passing back error/status codes, and method changes in different requests.', 'duration': 50.269, 'max_score': 5424.98, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5424980.jpg'}], 'start': 4627.954, 'title': 'Node.js server configuration, error handling, and crud operations', 'summary': 'Discusses configuring a node.js server, handling errors, creating database entries, and covering crud operations with examples of missed steps, mongoose methods, and restful api functionalities.', 'chapters': [{'end': 4687.408, 'start': 4627.954, 'title': 'Node.js server configuration', 'summary': 'Discusses the process of configuring a node.js server, including identifying missed steps such as exporting the module and importing it, and handling unrecognized routes with the 404 handler.', 'duration': 59.454, 'highlights': ['The chapter emphasizes the importance of exporting the module and importing it correctly in the Node.js server configuration process, highlighting the significance of these steps in avoiding errors and ensuring proper functionality.', 'It also mentions the significance of handling unrecognized routes through the 404 handler, showcasing the relevance of this aspect in providing a seamless user experience on the server.']}, {'end': 5014.064, 'start': 4688.068, 'title': 'Handling errors and creating entries in database', 'summary': 'Covers handling errors, creating entries in the database, and using mongoose methods, with examples of error codes, response statuses, and data validation.', 'duration': 325.996, 'highlights': ['The chapter covers handling errors, creating entries in the database, and using Mongoose methods The transcript discusses handling errors, creating entries in the database, and utilizing Mongoose methods for data validation and retrieval.', 'Examples of error codes, response statuses, and data validation are provided The transcript provides examples of error codes like 500 for internal server error, response status 201 for successful creation, and validation for required fields like email.', 'The usage of findOne method in Mongoose and its parameter passing is explained The usage of the findOne method in Mongoose for searching data based on query parameters like email is explained, emphasizing the need to handle both successful and error responses.']}, {'end': 5500.752, 'start': 5014.304, 'title': 'Crud operations in node.js', 'summary': 'Covers the basic crud operations in node.js, demonstrating the create, read, update, and delete functionalities using restful api methods, such as post, get, put, and delete, with examples and explanations of handling request body, query parameters, and response handling.', 'duration': 486.448, 'highlights': ['The chapter covers the basic CRUD operations in Node.js, demonstrating the create, read, update, and delete functionalities using RESTful API methods. It includes examples and explanations of handling request body, query parameters, and response handling.', 'The RESTful setup for CRUD operations involves using post, get, put, and delete methods. The post method is used for creating, the get method for retrieving, the put method for updating, and the delete method for deleting data.', 'The chapter demonstrates how to handle request body and query parameters in the CRUD operations, with specific examples. It explains how to check for email presence in the query and how to pass options objects, such as returning the newly created or updated object.', 'Error handling and response status codes are emphasized in the chapter. The chapter discusses error handling and the importance of passing back the correct status codes in the response.', "The chapter provides a detailed explanation of using promises for handling different error conditions in the CRUD operations. It demonstrates the use of promises with 'then' and 'catch' to handle different error conditions."]}], 'duration': 872.798, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM4627954.jpg', 'highlights': ['The chapter covers the basic CRUD operations in Node.js, demonstrating the create, read, update, and delete functionalities using RESTful API methods.', 'The chapter emphasizes the importance of exporting the module and importing it correctly in the Node.js server configuration process, highlighting the significance of these steps in avoiding errors and ensuring proper functionality.', 'The chapter discusses error handling and the importance of passing back the correct status codes in the response.', 'The usage of the findOne method in Mongoose for searching data based on query parameters like email is explained, emphasizing the need to handle both successful and error responses.', 'The RESTful setup for CRUD operations involves using post, get, put, and delete methods. The post method is used for creating, the get method for retrieving, the put method for updating, and the delete method for deleting data.']}, {'end': 5925.363, 'segs': [{'end': 5558.595, 'src': 'embed', 'start': 5529.853, 'weight': 0, 'content': [{'end': 5539.585, 'text': 'that essentially allows you to deploy your Node.js applications real quick.', 'start': 5529.853, 'duration': 9.732}, {'end': 5546.132, 'text': "And so I will let you explore this, but what I'm going to do is simply deploy this to the cloud now.", 'start': 5540.245, 'duration': 5.887}, {'end': 5551.694, 'text': 'And so what I need to do is go into my application folder and I type in now.', 'start': 5546.753, 'duration': 4.941}, {'end': 5558.595, 'text': 'I have the now client installed via NPM as a global and they have all the instructions here on this site.', 'start': 5551.974, 'duration': 6.621}], 'summary': 'Demonstrates quick deployment of node.js applications using now, with global npm client installation.', 'duration': 28.742, 'max_score': 5529.853, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5529853.jpg'}, {'end': 5612.013, 'src': 'embed', 'start': 5580.942, 'weight': 2, 'content': [{'end': 5591.63, 'text': "It will, um, upload that to the server side and then it's unzipping it and it is running the NPM install command,", 'start': 5580.942, 'duration': 10.688}, {'end': 5596.654, 'text': 'which ends up setting up all the dependencies, uh, that we require for the project.', 'start': 5591.63, 'duration': 5.024}, {'end': 5603.668, 'text': "And, um, Here you see it's giving you a status about what's going on.", 'start': 5597.774, 'duration': 5.894}, {'end': 5604.73, 'text': 'So it..', 'start': 5604.349, 'duration': 0.381}, {'end': 5609.151, 'text': 'did a bunch of things here.', 'start': 5608.15, 'duration': 1.001}, {'end': 5612.013, 'text': "It's telling you which version of Node it's using.", 'start': 5610.131, 'duration': 1.882}], 'summary': 'Server uploads, unzips, runs npm install to set up project dependencies and provides node version status.', 'duration': 31.071, 'max_score': 5580.942, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5580942.jpg'}, {'end': 5717.762, 'src': 'embed', 'start': 5693.351, 'weight': 1, 'content': [{'end': 5701.074, 'text': "And since we were using MLAB you know it's connected to the database we didn't have to worry about uploading the database or installing a database and things like that.", 'start': 5693.351, 'duration': 7.723}, {'end': 5710.098, 'text': "Of course, you would need to have a config file that then looks at the type of environment you're running in development staging,", 'start': 5701.695, 'duration': 8.403}, {'end': 5715.221, 'text': 'test production and then use the appropriate values from there to connect to the appropriate databases.', 'start': 5710.098, 'duration': 5.123}, {'end': 5717.762, 'text': 'But here you go.', 'start': 5717.001, 'duration': 0.761}], 'summary': 'Mlab simplifies database connection, utilizing config files for different environments.', 'duration': 24.411, 'max_score': 5693.351, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5693351.jpg'}, {'end': 5761.43, 'src': 'embed', 'start': 5734.591, 'weight': 3, 'content': [{'end': 5741.416, 'text': 'The new MongoDB driver is definitely a lot more powerful lately where it allows you to do validations as well.', 'start': 5734.591, 'duration': 6.825}, {'end': 5742.797, 'text': 'You can define a lot of those things.', 'start': 5741.496, 'duration': 1.301}, {'end': 5745.079, 'text': 'Several people prefer that approach.', 'start': 5743.477, 'duration': 1.602}, {'end': 5748.301, 'text': 'I personally have been using Mongoose for a while,', 'start': 5745.819, 'duration': 2.482}, {'end': 5761.43, 'text': "so I stick with it because I'm familiar with the API and it provides us with a lot of rich methods to handle these interfaces into the database.", 'start': 5748.301, 'duration': 13.129}], 'summary': 'New mongodb driver is powerful, allows validations, preferred by several, mongoose provides rich methods for database interfaces.', 'duration': 26.839, 'max_score': 5734.591, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5734591.jpg'}], 'start': 5501.653, 'title': 'Deploying node.js application and mongodb in react', 'summary': 'Covers deploying a node.js application to the cloud using now.sh, highlighting the ease and speed of deployment, including zipping, uploading, setting up dependencies, and accessing the application endpoint. it also explores using mlab, mongodb driver, mongoose, and the benefits of understanding building blocks for creating express servers and using webpack.', 'chapters': [{'end': 5692.851, 'start': 5501.653, 'title': 'Deploying node.js application to the cloud', 'summary': 'Discusses deploying a node.js application to the cloud using now.sh, showcasing the ease and speed of deploying and running the application, including the zipping and uploading process, setting up dependencies, and accessing the application endpoint.', 'duration': 191.198, 'highlights': ['Deploying the Node.js application to the cloud using now.sh, showcasing the ease and speed of deployment and running the application.', 'The zipping and uploading process of the application to the server side, followed by the unzipping and running the NPM install command to set up all the dependencies.', 'The creation of an actual endpoint for the application and the syncing of files, along with the initialization of the build process and the use of package-lock.json to replicate exact versions of libraries used.', 'Setting the process environment variable in package.json and ensuring the application is up and running in the cloud, with the demonstration of accessing the application endpoint in the browser.']}, {'end': 5925.363, 'start': 5693.351, 'title': 'Mongodb, mongoose, and react', 'summary': 'Discusses the ease of using mlab, the flexibility of mongodb driver, the option of using mongoose, and the benefits of understanding building blocks for creating express servers and using webpack.', 'duration': 232.012, 'highlights': ['MLAB provides quick and easy database connections Using MLAB eliminates the need to upload or install a database, allowing for quick application setup.', 'Flexibility of MongoDB driver for validations The new MongoDB driver offers powerful validations, enabling defining and handling various aspects more effectively.', 'Mongoose provides rich methods and plug-in model Mongoose offers rich methods and a plug-in model, simplifying complex database operations and providing familiarity with the API.', 'Understanding building blocks for creating express servers and using Webpack The importance of understanding the underlying building blocks for creating express servers and using Webpack, to comprehend the fundamental aspects of application development.']}], 'duration': 423.71, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/o3ka5fYysBM/pics/o3ka5fYysBM5501653.jpg', 'highlights': ['Deploying the Node.js application to the cloud using now.sh, showcasing the ease and speed of deployment and running the application.', 'MLAB provides quick and easy database connections Using MLAB eliminates the need to upload or install a database, allowing for quick application setup.', 'The zipping and uploading process of the application to the server side, followed by the unzipping and running the NPM install command to set up all the dependencies.', 'Flexibility of MongoDB driver for validations The new MongoDB driver offers powerful validations, enabling defining and handling various aspects more effectively.']}], 'highlights': ['Covers connecting to mongodb with mongoose, creating a crud api, defining a customer schema, setting up mongoose model for customer schema with validation, creating express routes for crud operations, and using the body-parser module for handling json data in the request body.', 'Deploying the Node.js application to the cloud using now.sh, showcasing the ease and speed of deployment and running the application.', 'HTTP is an application layer protocol defining rules for transferring resources between client and server.', 'Express is a lightweight web server that allows you to communicate via RESTful endpoints, integrating with Node.js HTTP classes.', 'The chapter covers the basic CRUD operations in Node.js, demonstrating the create, read, update, and delete functionalities using RESTful API methods.']}