[Node.js]25. Level 5. Route params
2023-09-14 09:00:56 时间
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);
相关文章
- JS对象转数组_js怎么把数组转成对象
- JS获取当前年份_js获取当前时间年月日
- Node.JS 安装配置 | 安装排错解析
- 开箱即用!Node.js+Mysql模块封装
- js正则表达式转义字符-【JavaScript正则表达式RegExp】
- JavaScript日期处理不再难!Day.js带你飞!
- Node.js 相关资料网站汇总详解编程语言
- node.js module初步理解详解编程语言
- js jquery数组去重详解编程语言
- Node.js连接MySQL数据库实践(node连接mysql)
- 版本Linux下查看Node版本号的方法(linux查看node)
- Linux环境下配置Node.js(linux配置node)
- 数据Node.js实现MySQL数据的同步更新(node同步mysql)
- Node.js连接MSSQL数据库的操作指南(node 链接mssql)
- JS实现获取打开一个界面中输入的值
- 以JSON形式将JS中Array对象数组传至后台的方法
- node.js中的fs.linkSync方法使用说明
- node.js中的fs.realpath方法使用说明
- node.js中的fs.readlink方法使用说明
- node.js中的fs.exists方法使用说明
- Express作者TJ告别Node.js奔向Go