[Express] Level 5: Route file】的更多相关文章

Using a Router Instance Let's refactor app.js to use a Router object. Create a new router object and assign it to the router variable. var router = express.Router(); When we are done, our router will be mounted on the /cities path. With this in mind,…
Route Instance Let's rewrite our cities routes using a Route Instance. Create a new Route Instance for the '/cities' URL path and assign it to thecitiesRoute variable. var citiesRoute = app.route('/cities'); Move the code from our previous app.get() …
Mounting Middleware Given an application instance is set to the app variable, which of the following function calls would you use to mount a middleware called logger ? Answer: app.use(logger); Default Middleware What is the only middleware that's shi…
Response Body What would the response body be set to on a DELETE request to /cities/DoesNotExist ? Here's the link to the sendStatus function source code if you need to take a look. Answer: 404 Delete Route Create a Dynamic Route for deleting cities…
Parser Setup Assume the body-parser middleware is installed. Now, let's use it in our Express application. npm install body-parser Require the body-parser npm module and assign it to a variable calledbodyParser. var bodyParser = require('body-parser'…
Flexible Routes Our current route only works when the city name argument matches exactly the properties in the cities object. This is a problem. We need a way to make our code more flexible. Inside our route, call the parseCityName() function passing…
City Search We want to create an endpoint that we can use to filter cities. Follow the tasks below to to create this new route. Create a new route for GET request to '/cities'. The second argument should be a callback function which takes request and…
Logging Middleware Help finish the following middleware code in the logger.js file: On the response object, listen to the event that's emitted when the response has been handed off from Express to the underlying Operating System. response.on('finish'…
Installing Express Let's start building our new Express application by installing Express. Type the command that installs the latest version for the 4.9 branch. npm install express@4.9 The '@' symbol to tell the npm which express version you want to…
哈哈,敢开源,还是要有两把刷子的啊 今天,看看node.js 的web框架 Express的实际应用 //demo1 upload file <html><head><title>文件上传表单</title></head><body><h3>文件上传:</h3>选择一个文件上传: <br /><form action="/file_upload" method="…