node-restful-api-tutorial | repository accompanies my YouTube series | Runtime Evironment library
kandi X-RAY | node-restful-api-tutorial Summary
kandi X-RAY | node-restful-api-tutorial Summary
This repository accompanies my YouTube series on building a RESTful API with Node.js: https://www.youtube.com/playlist?list=PL55RiY5tL51q4D-B63KBnygU6opNPFk_q
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of node-restful-api-tutorial
node-restful-api-tutorial Key Features
node-restful-api-tutorial Examples and Code Snippets
Community Discussions
Trending Discussions on node-restful-api-tutorial
QUESTION
I am new and learning Node Express with MongoDB 4.0 from various onlines sources. When I go through two different tutorials, I messed up with its different coding style.
Tutorial 1 : Callicoder Tutorial
Tutorial 2 : Academind Tutorial
I am confusing on the following topics in the both tutorials.
...ANSWER
Answered 2018-Aug-11 at 17:34Think of Express as an incredibly lightweight and basic framework that's very closely wrapped around the core of NodeJS. Most of the problems you're having aren't Express specific, they're just different npm packages that extend or alter the core functionality.
The way that the data is parsed by the application matters. Academind can handle image uploads because it uses the
multer
package. This is a middleware that handles any requests done with themultipart/form-data
encoding type, which is how images are sent to the server. Expected encoding types are also the answer to #5.The two files are just personal preference. You can do everything in one file, but many people like to require the
app.js
in theirserver.js
to further separate the "duties" of each file.This is similar to above, how they're separating the duties of the files even further. If you look closely, both are eventually ending up being called with the router. By creating Controller files in one of the projects they're separating whats called the "business logic" from the route definitions. It does the same thing, but some consider it more organized.
Are the two parameters vs three parameters
req, res, next
? If so, those are actually available for every single route in express. A lot of the time you don't neednext
in your code so programmers will just leave it out.This comes back to the expected encoding type of your request. Various middleware will handle and allow different encoding-types as needed. https://github.com/expressjs/body-parser is probably the most popular one as it's built into expressjs. This is how it interprets the requests you make and sets the req.body object. The "params" type actually sets the values as part of the url, appending them like so: 127.0.0.1:3000?param1=test¶m2=test. Where form-data is a part of the request that's being made and isn't available as a get parameter.
I hope this helps make more sense for you!
Edit: Based on your comment below, NodeJS functions using a lot of different middleware. Theoretically you could do this any number of times if you want to, and just keep using next to go to the next function in the middleware.
Ex:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install node-restful-api-tutorial
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page