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 did in previous levels (and then close the response).

var express = require('express');
var app = express.createServer(); var quotes = {
'einstein': 'Life is like riding a bicycle. To keep your balance you must keep moving',
'berners-lee': 'The Web does not just connect machines, it connects people',
'crockford': 'The good thing about reinventing the wheel is that you can get a round one',
'hofstadter': 'Which statement seems more true: (1) I have a brain. (2) I am a brain.'
};
app.get('/quotes/:name', function(request, response){
var quote = quotes[request.params.name];
response.end(quote);
});
app.listen(8080);

[Node.js]25. Level 5. Route params的更多相关文章

  1. [Node.js]26. Level 5 : Route rendering

    Instead of just writing out the quote to the response, instead render the quote.ejs template, passin ...

  2. [Node.js]30. Level 6: Listen 'Question' from client, and then Answer the Question

    Clients can also answer each other questions, so let's build that feature by first listening for the ...

  3. [Node.js]24. Level 5: Express, Express routes

    Create an express route that responds to GET requests at the URL /tweets that responds with the file ...

  4. [Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands

    Let's start practicing using the redis key-value store from our node application. First require the  ...

  5. [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup

    Below we've already created an express server, but we want to start building a real-time Q&A mod ...

  6. [Node.js]23. Level 4: Semantic versioning

    Update the versions on your dependencies to be a little more flexible, adding the ~ in front of your ...

  7. [Node.js]22. Level 4: Dependency

    Add two dependencies to your package.json file, connect and underscore. You'll want to useconnect ve ...

  8. [Node.js]33. Level 7: Persisting Questions

    Let's go back to our live-moderation app and add some persistence, first to the questions people ask ...

  9. [Node.js]32. Level 7: Working with Lists -- Redis

    As we saw in the video, redis can do more than just simple key-value pairs. We are going to be using ...

随机推荐

  1. 冒泡排序(高级版)之C++实现

    冒泡排序(高级版)之C++实现 一.源代码:BubbleSortHigh.cpp #include<iostream> using namespace std; /*定义输出一维数组的函数 ...

  2. [luogu4389]付公主的背包(多项式exp)

    完全背包方案计数问题的FFT优化.首先写成生成函数的形式:对重量为V的背包,它的生成函数为$\sum\limits_{i=0}^{+\infty}x^{Vi}=\frac{1}{1-x^{V}}$于是 ...

  3. [POI2000]Repetitions

    题目大意: 求多个字符串的LCS. 思路: 同SPOJ-LCS2,不过因为SPOJ上数据比较水,当时用错误的写法过掉了,这次用正确的写法重新过了一遍. 拓扑排序按照每个状态的len值,用计数排序实现. ...

  4. [BJOI2010]次小生成树

    OJ题号: BZOJ1977.COGS2453 题目大意: 给你一个无向连通图,求严格次小生成树. 思路: 对于一般次小生成树,我们有一个结论:一般次小生成树一定可以通过替换掉最小生成树某一条边得到. ...

  5. Git 初学者使用指南及Git 资源整理

    Git 资源整理 Git is a free and open source distributed version control system designed to handle everyth ...

  6. 2018-2019-20172329 《Java软件结构与数据结构》第二周学习总结

    2018-2019-20172329 <Java软件结构与数据结构>第二周学习总结 教材学习内容总结 <Java软件结构与数据结构>第三章 集合概述--栈 一.集合 1.我们印 ...

  7. 安装gitlab管理自己的代码

    安装gitlab的资料网上搜索很多,但发现很多都是比较老的资料了.我把我安装的过程记录一下,应该是最简单的过程了 1. 到 https://about.gitlab.com/downloads/ 下载 ...

  8. poj 1466 Girls and Boys 二分图的最大匹配

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  9. JQ中get()与eq()的区别

    .eq() : 减少匹配元素的集合,根据index索引值,精确指定索引对象. .get() : 通过检索匹配jQuery对象得到对应的DOM元素. 同样是返回元素,那么eq与get有什么区别呢? eq ...

  10. Linux下nmon工具安装及nmon analyser的使用

    步骤一:下载nmon及nmon analyser工具 nmon:http://nmon.sourceforge.net/pmwiki.php 根据自己系统的版本下载相应的版本即可 nmon analy ...