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() …
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,…
For server.js, we update the code by using route instance. By using this, we can remove some duplicate code. For example: app.get('/people', function(request, response){}); app.post('/people', parseUrlencoded, function(request, response){}); app.get(…
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…
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'…
Create a route that responds to a GET request '/quotes/<name>', then use the param from the URL to retrieve a quote from the quotes object and write it out to the response. Note: No piping here, just write the quote string to the response like you d…
Instead of just writing out the quote to the response, instead render the quote.ejs template, passing in the quote name and quote body. Then finish the quote.ejs view, by printing out the quote name and body. var express = require('express'); var app…
When we start to accumulate functions that all work on a given datatype, we end up creating a bunch of boilerplate code in almost every function to handle the changes we need to make to our records’ values. This can lead to not only undesirable boile…
After understanding how Box is, then we are going to see how to use Box to refacotr code, to un-nested expression. For example, we have code: const moneyToFloat = str => { const cost = str.replace(/\$/g, ''); return parseFloat(cost); } const percentT…
Currently, the server.js is going way too long. In the real world application, it is likely that we are going to deal with more routers, whichi means it growing even longer. A single file which has too many lines of code whcih means code small. We ar…
BookNote: Refactoring - Improving the Design of Existing Code From "Refactoring - Improving the Design of Existing Code" by Martin Flower. BookNote: Refactoring - Improving the Design of Existing Code Duplicated Code Long Method Large Class Long…
源自:http://www.cnblogs.com/panchunting/tag/Code%20First/ 1 Conventions 2 Custom Conventions 3 Data Annotations 4 Fluent API - 配置属性/类型 5 Fluent API - 配置关系 6 存储过程 7 空间数据类型 Spatial Data Types 8 迁移 Migrations (一)Conventions Entity Framework 简言之就是一个ORM(Obj…
创建初始模型和数据库 在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个新的控制台应用程序 MigrationsDemo; 添加最新的 EntityFramework 到项目 Tools –> Library Package Manager –> Package Manager Console; 运行命令 Install-Package EntityFramework…
URL的组成部分 协议: 协议确定如何传输请求.我们主要是处理http和https.其他常见的协议还有file和ftp. 主机名: 主机名标识服务器.运行在本地计算机(localhost)和本地网络的服务器可以简单地表示,比如用一个单词,或一个数字IP地址.在Internet环境下,主机名通常以一个顶级域名(TLD)结尾,比如.com或.net.另外,也许还会有子域名作为主机名的前缀.子域名可以是任何形式的,其中www最为常见.子域名通常是可选的. 端口: 每一台服务器都有一系列端口号.一些端口…
Coffee on the Range Create an array with numbers 1 until 10 using the inclusive (two dot) range syntax. [1..10] Coffee on the Range II Create an array with numbers 1 through 10 using the exclusive range syntax. Exclusive ranges are defined using thre…
在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个新的控制台应用程序 MigrationsDemo; 添加最新的 EntityFramework 到项目 Tools –> Library Package Manager –> Package Manager Console; 运行命令 Install-Package EntityFramework   创建 Blog.…
转:http://www.sigvc.org/bbs/thread-72-1-1.html 一.特征提取Feature Extraction:   SIFT [1] [Demo program][SIFT Library] [VLFeat]   PCA-SIFT [2] [Project]   Affine-SIFT [3] [Project]   SURF [4] [OpenSURF] [Matlab Wrapper]   Affine Covariant Features [5] [Oxfo…
本文转自:https://code.visualstudio.com/docs/nodejs/angular-tutorial Using Angular in Visual Studio Code Angular is a popular JavaScript library for building web application user interfaces developed by Google. The Visual Studio Code editor supports Angul…
序:这是一篇发表在2003年6月刊的MSDN Magazine的文章,现在已经不能在线阅读,只提供chm下载.讲的是异步请求处理那些事,正是我上一篇博文涉及的东西(BTW,事实上这篇杂志阐述了那么搞然并卵),期间有搜索到这篇文章,很受裨益.担心MS哪么时候不再提供下载以及本地保管不便,所以现在誊上来,作为备份,方便日后回顾. Fritz Onion This article assumes you're familiar with C#, ASP.NET, and MultithreadingL…
http://clrprofiler.codeplex.com/ http://blogs.msdn.com/b/davbr/archive/2012/11/19/clrprofiler-4-5-released-includes-windows-store-app-support.aspx Rewrite MSIL Code on the Fly with the .NET Framework Profiling API Aleksandr Mikunov This article assum…
经常遇到的exception是: 1. PipeMapRed.waitOutputThreads(): subprocess failed with code N  ............ 2. Task process exit with nonzero status of  N ............ java.lang.Throwable: Child Errorat org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.java:271…
PipeMapRed.waitOutputThreads(): subprocess failed with code X ,这里code X对应的信息如下:error code 1: Operation not permittederror code 2: No such file or directoryerror code 3: No such processerror code 4: Interrupted system callerror code 5: Input/output er…
在用 Express 构建 Web 服务器时,大部分工作都是从请求对象开始,到响应对象终止. url的组成: 协议协议确定如何传输请求.我们主要是处理 http 和 https.其他常见的协议还有 file 和 ftp.主机名主机名标识服务器.运行在本地计算机(localhost)和本地网络的服务器可以简单地表示,比如用一个单词,或一个数字 IP 地址.在 Internet 环境下,主机名通常以一个顶级域名(TLD)结尾,比如 .com 或 .net.另外,也许还会有子域名作为主机名的前缀.请求…
原文传送门:http://www.2cto.com/database/201308/236519.html "OS error code 1: Operation not permitted" "OS error code 2: No such file or directory" "OS error code 3: No such process" "OS error code 4: Interrupted system call&q…
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Fo…