Video 15 of Node JS Tutorial, thenewboston
Video Name: Connect
- a server framework called "connect" - already contains many tools we can use to handle user requests
- to install the "connect" framework, type "npm install connect" into the terminal
- when you connect to the website, it will look to the code for how to handle the request
- the code that handles user requests is called "middleware", place that in the "use" method/command
- the function of "connect" is that you can stack the middleware
- whenever you have a stack of middleware, these functions can be executed one by one
- doFirst has a special third parameter called next where whenever the user makes a request, you can make the function next (called doSecond) happen, basically calls for the next function - could be a very useful function in the future
- eventually, we can inspect paths, what user requests are they making, etc.
- a server framework called "connect" - already contains many tools we can use to handle user requests
- to install the "connect" framework, type "npm install connect" into the terminal
- when you connect to the website, it will look to the code for how to handle the request
- the code that handles user requests is called "middleware", place that in the "use" method/command
- the function of "connect" is that you can stack the middleware
- whenever you have a stack of middleware, these functions can be executed one by one
- doFirst has a special third parameter called next where whenever the user makes a request, you can make the function next (called doSecond) happen, basically calls for the next function - could be a very useful function in the future
- eventually, we can inspect paths, what user requests are they making, etc.
var connect = require('connect'); var http = require('http'); var app = connect(); function doFirst(request, response, next){ console.log("bacon") next(); } function doSecond(request, response, next){ console.log("tuna") next(); } app.use(doFirst); app.use(doSecond); http.createServer(app).listen(8888); console.log('Sever is now running.');Code used above.
No comments:
Post a Comment