[Node.js]25. Level 5. Route params
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的更多相关文章
- [Node.js]26. Level 5 : Route rendering
Instead of just writing out the quote to the response, instead render the quote.ejs template, passin ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [Node.js]22. Level 4: Dependency
Add two dependencies to your package.json file, connect and underscore. You'll want to useconnect ve ...
- [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 ...
- [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 ...
随机推荐
- Navicat Premium 激活码 序列号。破解版。
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha Navicat Premium 激活码 序列号.破解版.
- BZOJ3589动态树
**错误改了一上午. 先做熟练泼粪 k<=5,因此我们可以模拟这个过程,在线段树上把标记建出来然后pushup时候更新就好了. By:大奕哥 #include<bits/stdc++.h& ...
- LOJ P3959 宝藏 状压dp noip
https://www.luogu.org/problemnew/show/P3959 考场上我怎么想不出来这么写的,状压白学了. 直接按层次存因为如果某个点在前面存过了则肯定结果更优所以不用在意各点 ...
- Codeforces.724G.Xor-matic Number of the Graph(线性基)
题目链接 \(Description\) 给定一张带边权无向图.若存在u->v的一条路径使得经过边的边权异或和为s(边权计算多次),则称(u,v,s)为interesting triple(注意 ...
- [51Nod 1773] A国的贸易
[51Nod 1773] A国的贸易 题目描述 A国是一个神奇的国家. 这个国家有 2n 个城市,每个城市都有一个独一无二的编号 ,编号范围为0~2n-1. A国的神奇体现在,他们有着神奇的贸易规则. ...
- Alpha7
难受
- Opencv配套的辅助工具Image Watch
1.Image Watch 的下载链接. 2.OpenCV关于Image Watch的介绍页面链接. 3.OpenCV2.4 在线文档关于Image Watch的介绍文档. 4.更详细的信息参见I ...
- ConcurrentHashMap JDK 1.6 源码分析
前言 前段时间把 JDK 1.6 中的 HashMap 主要的一些操作源码分析了一次.既然把 HashMap 源码分析了, 就顺便把 JDK 1.6 中 ConcurrentHashMap 的主要一些 ...
- Java工程师成神之路 转
一.基础篇 1.1 JVM 1.1.1. Java内存模型,Java内存管理,Java堆和栈,垃圾回收 http://www.jcp.org/en/jsr/detail?id=133 http:/ ...
- ool _WebTryThreadLock(bool),
一般的问题是这样的 “bool _WebTryThreadLock(bool), 0xxxxxx: Tried to obtain the web lock from a thread other t ...