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 are going to extract routes to modules.

firstMean/routes/people.js:

/**
* Created by Answer1215 on 1/2/2015.
*/
var express = require('express');
var people = require('../controller/people');
//return router instance which can be mounted as a middleware
var router = express.Router(); router.route('/')
.get(people.getAll);
router.route('/:id')
.get(people.get); //exports the router as a Node module
module.exports = router;

Server.js:

'use strict';

var express = require('express');
var cors = require("cors");
var app = express();
app.use(cors()); var people = require('./routes/people');
//use router as a middleware
app.use('/people', people); app.listen(3000);

[MEAN Stack] First API -- 7. Using Route Files to Structure Server Side API的更多相关文章

  1. Laravel API Tutorial: How to Build and Test a RESTful API

    With the rise of mobile development and JavaScript frameworks, using a RESTful API is the best optio ...

  2. sql System.Data.SqlClient.SqlError: 无法覆盖文件 'C:\Program Files\Microsoft SQL Server\MSSQL\data\itsm_Data.MDF'。数据库 'my1' 正在使用该文件的解决方案

    对数据库备份进行还原时遇到“sql System.Data.SqlClient.SqlError: 无法覆盖文件 'C:\Program Files\Microsoft SQL Server\MSSQ ...

  3. Web API核查表:设计、测试、发布API时需思考的43件事[转]

    Web API核查表:设计.测试.发布API时需思考的43件事   当设计.测试或发布一个新的Web API时,你是在一个原有的复杂系统上构建新的系统.那么至少,你也要建立在HTTP上,而HTTP则是 ...

  4. 阿里云API网关(6)用户指南(开放 API )

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  5. 阿里云API网关(5)用户指南(调用 API)

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  6. 阿里云API网关(4)快速入门(开放 API)

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  7. 阿里云API网关(3)快速入门(调用 API)

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  8. Server的API如何设计才满足RESTful要求?

    Server的API如何设计才满足RESTful要求? 首先是简洁版里面的那几点.外加一些附带的 best practices:1. URL root: https://example.org/api ...

  9. docker报Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.19)

    docker version Client: Version: 17.05.0-ce API version: 1.24 (downgraded from 1.29) Go version: go1. ...

随机推荐

  1. HDU 5742 It's All In The Mind

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  2. WebView介绍

    本文主要对WebView进行介绍,包括webView 4个可以定制的点.设置WebView back键响应.控制网页的链接仍在webView中跳转.显示页面加载进度.处理https请求.利用addJa ...

  3. hdu 2594-Simpsons’ Hidden Talents(KMP)

    题意: 给你两个串a,b,求既是a的前缀又是b的后缀的最长子串的长度. 分析: 很自然的想到把两个串连接起来,根据KMP的性质求即可 #include <map> #include < ...

  4. JSP中字符编码转换问题

    问题描述:一个input.jsp页面中的参数,传递到另外一个save.jsp页面上,然后存入到数据库中,如果input.jsp页面输入偶数中文没有问题,输入奇数则出现?,存入数据库的也是?. 问题源码 ...

  5. C++实现网格水印之调试笔记(六)——补充

    调用matlab生成的网格水印特征向量矩阵 从文件中读取的原始网格的特征向量矩阵 好吧,之前得出的结果不正确是因为代码写错了.因为实现论文中的提取方案时代码写错了,自己想了另外一个方法,结果方向两者在 ...

  6. linux-制作linux启动U盘

    1. 使用的制作工具 Ø 下载需要制作启动盘的linux的iso文件 Ø 制作启动盘的软件linux usb creater Ø U盘(大小差不多需要4G的空间) 软件可以的下载的地址:http:// ...

  7. PackageManager获取版本号

    PackageInfo代表的是关于一个包的所有信息,就相当于一个APP应用的清单文件中收集到的所有信息. 通过这个类我们就可以获取类似版本号等一些信息. /** * 得到应用程序的版本名称 */ pr ...

  8. Windows 8.1及Windows8 JDK环境变量配置

    一.首先安装JDK JDK:http://www.oracle.com/technetwork/cn/java/javase/downloads/index.html 根据操作系统选择相应的版本 二. ...

  9. 【hbase】使用thrift with python 访问HBase

    HBase 版本: 0.98.6 thrift   版本: 0.9.0 使用 thrift client with python 连接 HBase 报错: Traceback (most recent ...

  10. 第二百八十九天 how can I 坚持

    今天好伤啊,太把自己当回事了. 现在在弟弟这,下午和他一块看了看西客站附近的房子,感觉暂时好难,只是暂时的,一切都会好起来的. 弟弟上班也挺不容易,不该来给他添麻烦,替他心疼. 确实不知道该咋办了,好 ...