chore(i8n,learn): processed translations (#41350)
* chore(i8n,learn): processed translations * fix: restore deleted test * fix: revert casing change Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
This commit is contained in:
committed by
GitHub
parent
8e4ada8f2d
commit
aff0ea700d
@@ -8,7 +8,7 @@ dashedName: get-data-from-post-requests
|
||||
|
||||
# --description--
|
||||
|
||||
在路径 `/name` 挂载一个 POST 处理方法, 和前面一样, 我们已经在 html 首页准备了一份表格, 它将提交与练习 10 相同的数据(查询字符串), 如果 body-parser 正确配置好了,那么就可以在 `req.body` 对象中找到请求的参数。 来看看一个常规的例子:
|
||||
在路径 `/name` 挂载一个 POST 处理方法, 和前面一样, 我们已经在 html 首页准备了一份表单, 它将提交与练习 10 相同的数据(查询字符串), 如果 body-parser 正确配置好了,那么就可以在 `req.body` 对象中找到请求的参数。 来看看一个常规的例子:
|
||||
|
||||
<blockquote>路由:POST '/library'<br>URL 编码的请求正文:userId=546&bookId=6754<br>req.body:{userId: '546', bookId: '6754'}</blockquote>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d7fb0367417b2b2512bed
|
||||
title: Meet the Node console
|
||||
title: 认识 Node 的控制台
|
||||
challengeType: 2
|
||||
forumTopicId: 301515
|
||||
dashedName: meet-the-node-console
|
||||
@@ -8,21 +8,27 @@ dashedName: meet-the-node-console
|
||||
|
||||
# --description--
|
||||
|
||||
During the development process, it is important to be able to check what’s going on in your code.
|
||||
可以采用下面的任意一种方式完成这些挑战:
|
||||
|
||||
Node is just a JavaScript environment. Like client side JavaScript, you can use the console to display useful debug information. On your local machine, you would see console output in a terminal. On Repl.it, a terminal is open in the right pane by default.
|
||||
- 克隆 [这个 GitHub 仓库](https://github.com/freeCodeCamp/boilerplate-express/) 并在本地完成项目。
|
||||
- 使用 [Repl.it 上的初始化项目](https://repl.it/github/freeCodeCamp/boilerplate-express) 来完成项目。
|
||||
- 使用你选择的网站生成器来完成项目, 并确保包含了我们 GitHub 仓库的所有文件。
|
||||
|
||||
We recommend to keep the terminal open while working at these challenges. By reading the output in the terminal, you can see any errors that may occur.
|
||||
当完成本项目,请确认有一个正常运行的 demo 可以公开访问。 然后将 URL 提交到 `Solution Link` 中。
|
||||
|
||||
在开发过程中,能够随时看到代码的运行结果是非常重要的。
|
||||
|
||||
Node 只是一个 JavaScript 环境。 与客户端 JavaScript 一样,你可以使用控制台显示有用的调试信息。 在本地计算机上,你可以在终端中输出调试信息。 在 Repl.it 上,右侧边栏会默认打开一个终端。
|
||||
|
||||
我们建议在做这些挑战题时保持终端打开的状态。 通过这些终端的输出,你可能会发现这些错误的本质原因。
|
||||
|
||||
# --instructions--
|
||||
|
||||
If you have not already done so, please read the instructions in [the introduction](/learn/apis-and-microservices/basic-node-and-express/) and start a new project on Repl.it using [this link](https://repl.it/github/freeCodeCamp/boilerplate-express).
|
||||
|
||||
Modify the `myApp.js` file to log "Hello World" to the console.
|
||||
修改 `myApp.js` 文件,在控制台打印出 “Hello World”。
|
||||
|
||||
# --hints--
|
||||
|
||||
`"Hello World"` should be in the console
|
||||
控制台应该输出 `"Hello World"`
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d7fb0367417b2b2512bf0
|
||||
title: Serve Static Assets
|
||||
title: 提供静态资源服务
|
||||
challengeType: 2
|
||||
forumTopicId: 301518
|
||||
dashedName: serve-static-assets
|
||||
@@ -8,21 +8,25 @@ dashedName: serve-static-assets
|
||||
|
||||
# --description--
|
||||
|
||||
An HTML server usually has one or more directories that are accessible by the user. You can place there the static assets needed by your application (stylesheets, scripts, images). In Express, you can put in place this functionality using the middleware `express.static(path)`, where the `path` parameter is the absolute path of the folder containing the assets. If you don’t know what middleware is... don’t worry, we will discuss in detail later. Basically, middleware are functions that intercept route handlers, adding some kind of information. A middleware needs to be mounted using the method `app.use(path, middlewareFunction)`. The first `path` argument is optional. If you don’t pass it, the middleware will be executed for all requests.
|
||||
HTML 服务器通常有一个或多个用户可以访问的目录。 你可以将应用程序所需的静态资源 (样式表、脚本、图片) 放在那里。
|
||||
|
||||
在 Express 中可以使用中间件 `express.static(path)` 来设置此功能,它的参数 `path` 就是包含静态资源文件的绝对路径。
|
||||
|
||||
如果你不知道什么是中间件……别担心,我们将在后面详细讨论。 其实,中间件就是一个拦截路由处理方法并在里面添加一些信息的函数。 使用 `app.use(path, middlewareFunction)` 方法来加载一个中间件, 它的第一个参数 `path` 是可选的, 如果没设置第一个参数,那么所有的请求都会经过这个中间件处理。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Mount the `express.static()` middleware for all requests with `app.use()`. The absolute path to the assets folder is `__dirname + /public`.
|
||||
使用 `app.use()` 为路径 `/public` 的请求安装 `express.static()` 中间件, 静态资源的绝对路径是 `__dirname + /public`。
|
||||
|
||||
Now your app should be able to serve a CSS stylesheet. From outside, the public folder will appear mounted to the root directory. Your front-page should look a little better now!
|
||||
现在应用应该能提供 CSS 样式表, 请注意, `/public/style.css` 文件被项目模板的 `/views/index.html` 引用, 首页应该更好看了。
|
||||
|
||||
# --hints--
|
||||
|
||||
Your app should serve asset files from the `/public` directory
|
||||
应用应该将资源文件从 `/public` 目录发送到 `/public` 路径
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
$.get(getUserInput('url') + '/style.css').then(
|
||||
$.get(getUserInput('url') + '/public/style.css').then(
|
||||
(data) => {
|
||||
assert.match(
|
||||
data,
|
||||
|
||||
@@ -28,7 +28,7 @@ name=John+Doe&age=25
|
||||
|
||||
在 `package.json` 中安装 `body-parser` 模块, 然后在文件顶部 `require` 进来, 用变量 `bodyParser` 保存它。 通过中间件的 `bodyParser.urlencoded({extended: false})` 方法处理 URL 编码数据, 将调用上个方法返回的函数传给 `app.use()`, 中间件通常挂载在所有需要它的路由之前。
|
||||
|
||||
**注意:**`extended=false`是一个告诉解析器使用经典编码的配置选项, 当使用它时,值只能是字符串或者数组, 拓展版本数据更加灵活,但稍逊于 JSON。
|
||||
**注意:**`extended=false` 是一个告诉解析器使用经典编码的配置选项, 当使用它时,值只能是字符串或者数组, 拓展版本数据更加灵活,但稍逊于 JSON。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d7fb1367417b2b2512bf2
|
||||
title: Use the .env File
|
||||
title: 使用 .env 文件
|
||||
challengeType: 2
|
||||
forumTopicId: 301521
|
||||
dashedName: use-the--env-file
|
||||
@@ -8,19 +8,19 @@ dashedName: use-the--env-file
|
||||
|
||||
# --description--
|
||||
|
||||
The `.env` file is a hidden file that is used to pass environment variables to your application. This file is secret, no one but you can access it, and it can be used to store data that you want to keep private or hidden. For example, you can store API keys from external services or your database URI. You can also use it to store configuration options. By setting configuration options, you can change the behavior of your application, without the need to rewrite some code.
|
||||
`.env` 文件是一个用于将环境变量传给应用程序的隐藏文件, 这是一个除了开发者之外没人可以访问的私密文件,它可以用来存储你想保密或者隐藏的数据, 例如,它可以存储第三方服务的 API 密钥或者数据库 URI, 也可以使用它来存储配置选项, 通过设置配置选项,你可以改变应用程序的行为,而无需重写一些代码。
|
||||
|
||||
The environment variables are accessible from the app as `process.env.VAR_NAME`. The `process.env` object is a global Node object, and variables are passed as strings. By convention, the variable names are all uppercase, with words separated by an underscore. The `.env` is a shell file, so you don’t need to wrap names or values in quotes. It is also important to note that there cannot be space around the equals sign when you are assigning values to your variables, e.g. `VAR_NAME=value`. Usually, you will put each variable definition on a separate line.
|
||||
在应用程序中可以通过 `process.env.VAR_NAME` 访问到环境变量。 `process.env` 对象是 Node 程序中的一个全局对象,可以给这个变量传字符串。 习惯上,变量名全部大写,单词之间用下划线分隔。 `.env` 是一个 shell 文件,因此不需要用给变量名和值加引号。 还有一点需要注意,当你给变量赋值时等号两侧不能有空格,例如:`VAR_NAME=value`。 通常来讲,每一个变量定义会独占一行。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Let's add an environment variable as a configuration option.
|
||||
添加一个环境变量作为配置选项。
|
||||
|
||||
Store the variable `MESSAGE_STYLE=uppercase` in the `.env` file. Then tell the GET `/json` route handler that you created in the last challenge to transform the response object’s message to uppercase if `process.env.MESSAGE_STYLE` equals `uppercase`. The response object should become `{"message": "HELLO JSON"}`.
|
||||
在项目根目录创建一个 `.env` 文件,并存储变量 `MESSAGE_STYLE=uppercase`。 当向 `/json` 发 GET 请求时,如果 `process.env.MESSAGE_STYLE` 的值为 `uppercase`,那么上一次挑战中的路由处理程序返回的对象的消息则应该大写, 即响应对象应该是 `{"message": "HELLO JSON"}`。
|
||||
|
||||
# --hints--
|
||||
|
||||
The response of the endpoint `/json` should change according to the environment variable `MESSAGE_STYLE`
|
||||
端口 `/json` 响应的值,应该随着环境变量 `MESSAGE_STYLE` 的变化而改变
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
||||
Reference in New Issue
Block a user