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).

  1. var express = require('express');
  2. var app = express.createServer();
  3.  
  4. var quotes = {
  5. 'einstein': 'Life is like riding a bicycle. To keep your balance you must keep moving',
  6. 'berners-lee': 'The Web does not just connect machines, it connects people',
  7. 'crockford': 'The good thing about reinventing the wheel is that you can get a round one',
  8. 'hofstadter': 'Which statement seems more true: (1) I have a brain. (2) I am a brain.'
  9. };
  10. app.get('/quotes/:name', function(request, response){
  11. var quote = quotes[request.params.name];
  12. response.end(quote);
  13. });
  14. 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. android 视频 2017

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha

  2. hdu 2819 记录路径的二分匹配

    题目大意就是给出一个矩阵,每个格子里面要么是0, 要么是1:是否能够经过交换(交换行或者列)使得主对角线上都是1. 其实就行和列的匹配,左边是行,右边是列,然后如果行列交点是1,那么就可以匹配,看是否 ...

  3. opencv第三课 Canny边缘检测

    #include<stdio.h> #include<iostream> #include<opencv2\opencv.hpp> using namespace ...

  4. 最小生成树-普利姆算法lazy实现

    算法描述 lazy普利姆算法的步骤: 1.从源点s出发,遍历它的邻接表s.Adj,将所有邻接的边(crossing edges)加入优先队列Q: 2.从Q出队最轻边,将此边加入MST. 3.考察此边的 ...

  5. 仿querySeletor 兼容IE 67

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. FastBoot BootLoader Recovery 模式解释

    理论上,所有的Android设备都存在着Fastboot/Bootloader模式,不过,由于Android操作系统的开源特性,各厂商的对 自家的相关Android设备都有着各自不同的Fastboot ...

  7. How to match between physical usb device and its drive letter?

    struct tagDrives { WCHAR letter; WCHAR volume[ BUFFER_SIZE ]; } g_drives[ ]; // WCHAR GetUSBDrive( ) ...

  8. Canavs arcTo方法的理解

    arcTo方法有四个參数 參数1,2为第一个控制点的x,y坐标,參数2为第二个控制点的坐标,參数3为绘制圆弧的半径. 起点和第一个控制点组成的延长线与第一个控制点和第二个控制点组成的延长线都是和圆弧相 ...

  9. html圆形头像的制作

    <html> <head><title>圆形头像的制作</title> <style type="text/css">. ...

  10. 0x80070570 文件或目录损坏且无法读取 CHKDSK 修复方法

    错误 0x80070570: 文件或目录损坏且无法读取. 不要太担心是出现了磁盘坏道,也许只是小小的存储问题.解决方法很简单,用chsdsk命令即可. 方法如下: 开始--运行--输入cmd--输入c ...