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. hadoop2.20.0集群安装教程

    一.安装的需要软件及集群描述 1.软件: Vmware9.0:虚拟机 Hadoop2.2.0:Apache官网原版稳定版本 JDK1.7.0_07:Oracle官网版本 Ubuntu12.04LTS: ...

  2. KindEditor Asp.net

    最近在使用KindEditor,其中遇到三个问题: 1.textarea添加 runat="server" 后整个editor在运行的时候不能显示出来,我没找到原因,于是我就把ru ...

  3. html 5新特性 --用SVG绘制的微信logo

    一个简单的SVG绘制图片的小案例. 效果图: 代码如下: <style> * { ; ; } body { background-color: #d5d3d4; } .container ...

  4. 【C#】字符串与字符数组

    字符串与字符数组的相互转换. 字符串转换成字符数组: string ss="abcdefg"; char[] cc=ss.ToCharArray();     字符数组转换成字符串 ...

  5. PHP命名规范【转】

      [转]谭博的个人网站 [类] 1.类名与类文件名采用驼峰式且首字母大写 2.类私有属性和私有方法名称以下划线开头 3.方法名使用驼峰式 [变量] 变量名使用小写字母加下划线 [函数] 函数名使用小 ...

  6. Javascript手记-基本类型和引用类型

    1:ecmascript包含2中不同的数据类型,基本数值类型和引用数值类型.基本数据类型是简单的数据段,引用类型是指那些可能由多个值构成的对象. 1.1:常用的基本类型:Undefined,Null, ...

  7. cmake编译win下64位obs

    obs是一款开源编码推流工具,简单易用,非常流行.一次项目中,发现本台式机I3处理器下32位obs推流CPU使用率100%.而使用的第三方设备在64位下,性能较好.所以需要编译64位obs并且编译相应 ...

  8. struts2+Hibernate4+spring3+EasyUI环境搭建之五:引入jquery easyui

    1.下载jquery easyui组件     http://www.jeasyui.com/download/index.php 2.解压 放到工程中  如图 3.jsp引入组件:必须按照如下顺序 ...

  9. 教程-在F9后提示内存错误,点击了乎略,之后怎么取消乎略?

    问题现象:F9后,调试程序,提示内存错误,点击了“乎略”.之后再也没有出现错误了.可是想改这个BUG时,没法取消乎略了. 问题原因:在DLEPHI的选项中是这么一个地方是可以设置的. 问题处理:打开D ...

  10. POJ3278http://poj.org/problem?id=3278

    http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...