Files
freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/basic-node-and-express/start-a-working-express-server.chinese.md
Beau Carnes 6b1992ee7c fix: Add Api challenges - Chinese translation (#35164)
* fix: Add Api challenges - Chinese translation

* fix: md formatting

* fix: md formatting
2019-05-06 06:31:26 -05:00

2.2 KiB
Raw Blame History

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d7fb0367417b2b2512bee Start a Working Express Server 启动Working Express服务器 2

Description

0在myApp.js文件的前两行中您可以看到如何轻松创建Express应用程序对象。这个对象有几种方法我们将在这些挑战中学到很多方法。一个基本方法是app.listen(port) 。它告诉您的服务器侦听给定端口,使其处于运行状态。您可以在文件底部看到它。这是内部评论,因为出于测试原因,我们需要应用程序在后台运行。您可能想要添加的所有代码都介于这两个基本部分之间。 Glitch将端口号存储在环境变量process.env.PORT 。它的价值是30000让我们的第一个字符串在Express中路由采用以下结构 app.METHOD(PATH, HANDLER) 。 METHOD是小写的http方法。 PATH是服务器上的相对路径它可以是字符串甚至是正则表达式。 HANDLER是Express匹配路由时调用的功能。 0处理程序采用表单function(req, res) {...} 其中req是请求对象res是响应对象。例如处理程序
function(req, res) {
res.send('Response String');
}
0将提供字符串'Response String'。 0使用app.get()方法为字符串Hello Express提供服务以匹配/ root路径的GET请求。通过查看日志确保您的代码正常工作然后在浏览器中查看结果单击Glitch UI中的“Show Live”按钮。

Instructions

Tests

tests:
  - text: 您的应用应该提供字符串'Hello Express'
    testString: 'getUserInput => $.get(getUserInput(''url'')).then(data => { assert.equal(data, ''Hello Express'', ''Your app does not serve the text "Hello Express"''); }, xhr => { throw new Error(xhr.responseText); })'

Challenge Seed

Solution

// solution required