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('/people/:name', function(request, response){});
app.delete('/people/:name', function(request, response){});

There are a lot of '/people/'...

Using route instance:


app.route('/people')
.get(function(req ,res){})
.post(parseUrlEncoded, function(req, res){}); app.route('/people/:name')
.get(function(req, res){})
.delete(function(req, res){});

In our case:


before:

//server.js

'use strict';

var express = require('express');
var cors = require("cors");
var app = express();
app.use(cors());
var people = require('./controller/people'); app.get('/people', people.getAll);
app.get('/people/:id', people.get); app.listen(3000);

after:

'use strict';

var express = require('express');
var cors = require("cors");
var app = express();
app.use(cors());
var people = require('./controller/people'); app.route('/people')
.get(people.getAll);
app.route('/people/:id')
.get(people.get);
app.listen(3000);

[MEAN Stack] First API -- 6. Using Express route instance的更多相关文章

  1. [Express] Level 5: Route Instance -- refactor the code

    Route Instance Let's rewrite our cities routes using a Route Instance. Create a new Route Instance f ...

  2. 如何在ARM中创建Express Route

    很早之前就想试试Azure的express route,但是一直没有找到合适的机会,正好有个客户需要上express route,所以最近先自己研究研究,防止在做poc的时候耗费更多时间,本次场景我们 ...

  3. nodejs express route 的用法

    express 中文社区:http://expressjs.jser.us/community.html nodejs express route 的用法 1. 首先是最基本的用法. 1 2 3 4 ...

  4. 一根Express Route同时支持ARM和ASM的VNET

    ARM模式的Azure管理模式在China Azure上已经正式落地了.今后在China Azure上应该主要以ARM的模式创建VM了. 并且目前Express Route也已经可以在ARM模式下创建 ...

  5. ARM模式下创建Express Route

    在Azure的ARM模式下,创建Express Route的命令和ASM模式下是有一些区别的. 本文将介绍在ARM模式下,如果创建Express Route的Circuit. 1. 查看支持的Serv ...

  6. Express Route的配置

    ExpressRoute在中国已经Preview了. 本篇文章讲介绍ExpressRoute如何配置. Express Route的逻辑拓扑结构: 在配置Express Route之前,需要做VLAN ...

  7. 每日技术总结:promise,express route,评分,local storage商品浏览历史,

    最近正在用Vue做一个电商项目.利用工作前后空隙时间. 1.promise的使用 点这里 如何在实际项目中使用Promise 2. Express Route 前后端传参的两种方法 (1)req.pa ...

  8. [MEAN Stack] First API -- 3. Select by ID with Mongoose and Express

    Mongoose allows you to easily select resources by ID from your MongoDB. This is an important aspect ...

  9. [MEAN Stack] First API -- 1. with Node.js, Express and MongoDB

    Learn how to import data into your MongoDB and then use Express to serve a simple Node.js API. Impor ...

随机推荐

  1. 【转】u盘不显示盘符

    转自http://jingyan.baidu.com/article/f3ad7d0fd0793e09c3345b31.html 我的情况: 电脑只有一个c盘,插入u盘,u盘的盘符为d. 弹出u盘,但 ...

  2. 在PC上收发短信--Pidgin短信(Linux Pidgin插件)

    Pidgin短信是Pidgin/empathy的一个插件.当手机收到短信进,电脑上面有提示:可以在电脑上发手机短信.让你时刻保持在电脑屏幕上,也不会错过短信.目前只支持安卓,wifi连接方式. 功能 ...

  3. Flash Player”又来了“!

    2012年,Adobe宣布缩小对Linux平台的支持,自Flash Player 11.2版本之后,只为Linux平台上的Flash Player提供安全更新和bug修复,而不再提供版本更新. 四年之 ...

  4. codeforces 700B Connecting Universities 贪心dfs

    分析:这个题一眼看上去很难,但是正着做不行,我们换个角度:考虑每条边的贡献 因为是一棵树,所以一条边把树分成两个集合,假如左边有x个学校,右边有y个学校 贪心地想,让每条边在学校的路径上最多,所以贡献 ...

  5. JavaScript UI技术选型

    ExtJS l ExtJS(TODO:找旧版本,类似现在EasyUI插件的旧版本)简介:纯JS支持:IE6授权:GPLv3授权.商业授权($329/人) l Ext.NET简介:ExtJS的NET封装 ...

  6. Mahout分步式程序开发 聚类Kmeans(转)

    Posted: Oct 14, 2013 Tags: clusterHadoopkmeansMahoutR聚类 Comments: 13 Comments Mahout分步式程序开发 聚类Kmeans ...

  7. bzoj 1576 [Usaco2009 Jan]安全路经Travel(树链剖分,线段树)

    [题意] 给定一个无向图,找到1-i所有的次短路经,要求与最短路径的最后一条边不重叠. [思路] 首先用dijkstra算法构造以1为根的最短路树. 将一条无向边看作两条有向边,考察一条不在最短路树上 ...

  8. [LeetCode] #1# Two Sum : 数组/哈希表/二分查找/双指针

    一. 题目 1. Two SumTotal Accepted: 241484 Total Submissions: 1005339 Difficulty: Easy Given an array of ...

  9. HDU-4726 Kia's Calculation 贪心

    题目链接:http://acm.hdu.edu.cn/userstatus.php?user=zhsl 题意:给两个大数,他们之间的加法法则每位相加不进位.现在可以对两个大数的每位重新排序,但是首位不 ...

  10. Transform DataGrid 套用格式

    <table class="easyui-datagrid" title="Transform DataGrid" style="width:5 ...