博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[MEAN Stack] First API -- 7. Using Route Files to Structure Server Side API
阅读量:6560 次
发布时间:2019-06-24

本文共 905 字,大约阅读时间需要 3 分钟。

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 middlewarevar router = express.Router();router.route('/')    .get(people.getAll);router.route('/:id')    .get(people.get);//exports the router as a Node modulemodule.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 middlewareapp.use('/people', people);app.listen(3000);

 

转载地址:http://ntzjo.baihongyu.com/

你可能感兴趣的文章
Objective-C学习总结-13协议1
查看>>
web学习方向
查看>>
A*算法实现
查看>>
第一周 从C走进C++ 002 命令行参数
查看>>
【java】itext pdf 分页
查看>>
看看这个电脑的配置
查看>>
[转]【NoSQL】NoSQL入门级资料整理(CAP原理、最终一致性)
查看>>
RequireJS进阶(二)
查看>>
我设计的网站的分布式架构
查看>>
python基础学习笔记(十三)
查看>>
linux extract rar files
查看>>
Knockout.Js官网学习(监控属性Observables)
查看>>
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
查看>>
azure之MSSQL服务性能测试
查看>>
公众平台安全中心新增运营者微信号个数为四个 支持多人管理
查看>>
Android BitmapFactory.Options
查看>>
前端构建:Less入了个门
查看>>
Hibernate 自动生成数据库表
查看>>
phonegap(cordova) 自己定义插件代码篇(三)----支付宝支付工具整合
查看>>
博客更名为 健哥的数据花园
查看>>