chore(i18n,curriculum): update translations (#43463)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a8b073d06fa14fcfde687aa
|
||||
title: Exercise 追蹤器
|
||||
title: 運動追蹤器
|
||||
challengeType: 4
|
||||
forumTopicId: 301505
|
||||
dashedName: exercise-tracker
|
||||
@ -8,13 +8,55 @@ dashedName: exercise-tracker
|
||||
|
||||
# --description--
|
||||
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似: <https://exercise-tracker.freecodecamp.rocks/>。 可以採用下面的一種方式完成這個挑戰:
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似: <https://exercise-tracker.freecodecamp.rocks/>。 在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- 克隆 [GitHub 倉庫](https://github.com/freeCodeCamp/boilerplate-project-exercisetracker/) 並在本地完成你的項目。
|
||||
- 使用[我們的 Replit 初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-project-exercisetracker)來完成你的項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --instructions--
|
||||
|
||||
你的答案應該有以下結構。
|
||||
|
||||
運動:
|
||||
|
||||
```js
|
||||
{
|
||||
username: "fcc_test"
|
||||
description: "test",
|
||||
duration: 60,
|
||||
date: "Mon Jan 01 1990",
|
||||
_id: "5fb5853f734231456ccb3b05"
|
||||
}
|
||||
```
|
||||
|
||||
用戶:
|
||||
|
||||
```js
|
||||
{
|
||||
username: "fcc_test",
|
||||
_id: "5fb5853f734231456ccb3b05"
|
||||
}
|
||||
```
|
||||
|
||||
日誌:
|
||||
|
||||
```js
|
||||
{
|
||||
username: "fcc_test",
|
||||
count: 1,
|
||||
_id: "5fb5853f734231456ccb3b05",
|
||||
log: [{
|
||||
description: "test",
|
||||
duration: 60,
|
||||
date: "Mon Jan 01 1990",
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
**提示:** 對於 `date` 屬性,`Date` API 的 `toDateString` 方法可以用於實現預期的輸出。
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -29,7 +71,24 @@ dashedName: exercise-tracker
|
||||
};
|
||||
```
|
||||
|
||||
可以將表單裏的 `username` 通過 `POST` 請求發送到 `/api/users`,以創建一個新的用戶。 返回的響應內容是一個帶有 `username` 和 `_id` 的對象
|
||||
可以將表單裏的 `username` 通過 `POST` 請求發送到 `/api/users`,以創建一個新的用戶。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||
});
|
||||
assert.isTrue(res.ok);
|
||||
if(!res.ok) {
|
||||
throw new Error(`${res.status} ${res.statusText}`)
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
`POST /api/users` 帶有表單數據 `username` 對請求,返回的響應將是一個具有 `username` 和 `_id` 屬性的對象.
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -49,24 +108,89 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
可以發送 `GET` 請求到 `/api/users`,以獲取一個所有用戶的數組, 數組裏的每個元素都是一個包含 `username` 和 `_id` 的用戶對象。
|
||||
你可以向 `/api/users` 發出 `GET` 請求以獲取所有用戶的列表。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users');
|
||||
assert.isTrue(res.ok);
|
||||
if(!res.ok) {
|
||||
throw new Error(`${res.status} ${res.statusText}`)
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
對 `/api/users` 的 `GET` 請求返回一個數組。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users');
|
||||
if(res.ok){
|
||||
const users = await res.json();
|
||||
assert.isArray(users);
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
從 `GET /api/users` 返回的數組中的每個元素都是一個對象字面量,包含用戶的 `username` 和 `_id`。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users');
|
||||
if(res.ok){
|
||||
const users = await res.json();
|
||||
const user = users[0];
|
||||
assert.exists(user);
|
||||
assert.exists(user.username);
|
||||
assert.exists(user._id);
|
||||
assert.isString(user.username);
|
||||
assert.isString(user._id);
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
你能用表單裏的 `description`、`duration` 和 `date`(可選)發送 `POST` 請求到 `/api/users/:_id/exercises`。 如果沒有傳入 date,默認採用當前日期。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users');
|
||||
const res = await fetch(url + '/api/users', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
assert.isArray(data);
|
||||
assert.isString(data[0].username);
|
||||
assert.isString(data[0]._id);
|
||||
const { _id, username } = await res.json();
|
||||
const expected = {
|
||||
username,
|
||||
description: 'test',
|
||||
duration: 60,
|
||||
_id,
|
||||
date: 'Mon Jan 01 1990'
|
||||
};
|
||||
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
|
||||
});
|
||||
assert.isTrue(addRes.ok);
|
||||
if(!addRes.ok) {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`)
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
你能用表單裏的 `description`、`duration` 和 `date`(可選)發送 `POST` 請求到 `/api/users/:_id/exercises`。 如果沒有傳入 date,默認採用當前日期。 響應內容是包含 exercise 表單內容的 user 對象。
|
||||
從 `POST /api/users/:_id/exercises` 返回的響應將是添加了運動字段的用戶對象。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -93,6 +217,9 @@ async (getUserInput) => {
|
||||
if (addRes.ok) {
|
||||
const actual = await addRes.json();
|
||||
assert.deepEqual(actual, expected);
|
||||
assert.isString(actual.description);
|
||||
assert.isNumber(actual.duration);
|
||||
assert.isString(actual.date);
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
}
|
||||
@ -102,7 +229,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
可以發送 `GET` 請求到 `/api/users/:_id/logs`,以獲取任何用戶的完整 exercise 日誌。 響應內容是一個 user 對象,它帶有一個 `log` 屬性,該屬性的值是所有被添加的 exercises 表單記錄組成的數組, 每一個 log 數組裏的元素應該是一個含有 `description`、`duration` 和 `date` 等屬性的對象。
|
||||
可以發送 `GET` 請求到 `/api/users/:_id/logs`,以獲取任何用戶的完整 exercise 日誌。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -128,13 +255,10 @@ async (getUserInput) => {
|
||||
});
|
||||
if (addRes.ok) {
|
||||
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||
if (logRes.ok) {
|
||||
const { log } = await logRes.json();
|
||||
assert.isArray(log);
|
||||
assert.equal(1, log.length);
|
||||
} else {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||
}
|
||||
assert.isTrue(logRes.ok);
|
||||
if(!logRes.ok) {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`)
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
}
|
||||
@ -144,7 +268,7 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
用戶日誌請求(`/api/users/:_id/logs`)返回一個帶有 `count` 屬性的對象,該屬性反映 exercises 表單的成功提交次數(譯者注:即 log 屬性元素的個數)。
|
||||
對用戶日誌的請求 `GET /api/users/:_id/logs` 返回一個用戶對象,該對象具有一個 `count` 屬性,表示屬於該用戶的運動次數。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
@ -185,7 +309,239 @@ async (getUserInput) => {
|
||||
};
|
||||
```
|
||||
|
||||
可以把 `from`、`to` 和 `limit` 參數添加到一個 `/api/users/:_id/logs` 請求,以查詢該用戶的部分 exercise 表單提交記錄, `from` 和 `to` 是 `yyyy-mm-dd` 形式的日期, `limit` 是希望返回的 log 數量。
|
||||
對 `/api/users/:id/logs` 的 `GET` 請求將返回用戶對象,其中包含添加的所有練習的 `log` 數組。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||
})
|
||||
if(res.ok){
|
||||
const {_id, username} = await res.json();
|
||||
const expected = {
|
||||
username,
|
||||
description: 'test',
|
||||
duration: 60,
|
||||
_id,
|
||||
date: new Date().toDateString()
|
||||
};
|
||||
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: `description=${expected.description}&duration=${expected.duration}`
|
||||
});
|
||||
if(addRes.ok){
|
||||
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||
if(logRes.ok) {
|
||||
const {log} = await logRes.json();
|
||||
assert.isArray(log);
|
||||
assert.equal(1, log.length);
|
||||
} else {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`)
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
從 `GET /api/users/:id/logs` 返回的 `log` 數組中的每一項都是一個應該具有 `description` 的對象, `duration` 和 `date` 屬性。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + `/api/users`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
|
||||
});
|
||||
if(res.ok) {
|
||||
const {_id, username} = await res.json();
|
||||
const expected = {
|
||||
username,
|
||||
description: 'test',
|
||||
duration: 60,
|
||||
_id,
|
||||
date: new Date().toDateString()
|
||||
};
|
||||
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: `description=${expected.description}&duration=${expected.duration}`
|
||||
});
|
||||
if(addRes.ok) {
|
||||
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||
if(logRes.ok) {
|
||||
const {log} = await logRes.json();
|
||||
const exercise = log[0];
|
||||
assert.exists(exercise);
|
||||
assert.exists(exercise.description);
|
||||
assert.exists(exercise.duration);
|
||||
assert.exists(exercise.date);
|
||||
} else {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`)
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
從 `GET /api/users/:id/logs` 返回的 `log` 數組中任何對象的 `description` 屬性都應該是一個字符串。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0,29)
|
||||
});
|
||||
if(res.ok) {
|
||||
const {_id, username} = await res.json();
|
||||
const expected = {
|
||||
username,
|
||||
description: 'test',
|
||||
duration: 60,
|
||||
_id,
|
||||
date: new Date().toDateString()
|
||||
};
|
||||
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `description=${expected.description}&duration=${expected.duration}`
|
||||
});
|
||||
if(addRes.ok) {
|
||||
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||
if(logRes.ok){
|
||||
const {log} = await logRes.json();
|
||||
const exercise = log[0];
|
||||
assert.isString(exercise.description);
|
||||
assert.equal(exercise.description, expected.description);
|
||||
} else {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
從 `GET /api/users/:id/logs` 返回的 `log` 數組中任何對象的 `duration` 屬性都應該是一個數字。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0,29)
|
||||
});
|
||||
if(res.ok) {
|
||||
const {_id, username} = await res.json();
|
||||
const expected = {
|
||||
username,
|
||||
description: 'test',
|
||||
duration: 60,
|
||||
_id,
|
||||
date: new Date().toDateString()
|
||||
};
|
||||
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `description=${expected.description}&duration=${expected.duration}`
|
||||
});
|
||||
if(addRes.ok) {
|
||||
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||
if(logRes.ok){
|
||||
const {log} = await logRes.json();
|
||||
const exercise = log[0];
|
||||
assert.isNumber(exercise.duration);
|
||||
assert.equal(exercise.duration, expected.duration);
|
||||
} else {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
從 `GET /api/users/:id/logs` 返回的 `log` 數組中任何對象的 `date` 屬性應該是一個字符串。 使用 `Date` API 的 `dateString` 格式。
|
||||
|
||||
```js
|
||||
async(getUserInput) => {
|
||||
const url = getUserInput('url');
|
||||
const res = await fetch(url + '/api/users/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `username=fcc_test_${Date.now()}`.substr(0,29)
|
||||
});
|
||||
if(res.ok) {
|
||||
const {_id, username} = await res.json();
|
||||
const expected = {
|
||||
username,
|
||||
description: 'test',
|
||||
duration: 60,
|
||||
_id,
|
||||
date: new Date().toDateString()
|
||||
};
|
||||
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `description=${expected.description}&duration=${expected.duration}`
|
||||
});
|
||||
if(addRes.ok) {
|
||||
const logRes = await fetch(url + `/api/users/${_id}/logs`);
|
||||
if(logRes.ok){
|
||||
const {log} = await logRes.json();
|
||||
const exercise = log[0];
|
||||
assert.isString(exercise.date);
|
||||
assert.equal(exercise.date, expected.date);
|
||||
} else {
|
||||
throw new Error(`${logRes.status} ${logRes.statusText}`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`${addRes.status} ${addRes.statusText}`);
|
||||
};
|
||||
} else {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
你可以將 `from`、`to` 和 `limit` 參數添加到 `GET /api/users/:_id/logs` 請求檢索任何用戶的部分日誌。 `from` 和 `to` 是 `yyyy-mm-dd` 形式的日期, `limit` 是希望返回的 log 數量。
|
||||
|
||||
```js
|
||||
async (getUserInput) => {
|
||||
|
@ -8,13 +8,13 @@ dashedName: file-metadata-microservice
|
||||
|
||||
# --description--
|
||||
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://file-metadata-microservice.freecodecamp.rocks/>。 可以採用下面的一種方式完成這個挑戰:
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://file-metadata-microservice.freecodecamp.rocks/>。 在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- 克隆 [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-filemetadata/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-project-filemetadata)來完成你的項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -8,13 +8,13 @@ dashedName: request-header-parser-microservice
|
||||
|
||||
# --description--
|
||||
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://request-header-parser-microservice.freecodecamp.rocks/>。 可以採用下面的一種方式完成這個挑戰:
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://request-header-parser-microservice.freecodecamp.rocks/>。 在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- 克隆 [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-headerparser/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-project-headerparser)來完成你的項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -8,13 +8,13 @@ dashedName: timestamp-microservice
|
||||
|
||||
# --description--
|
||||
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://timestamp-microservice.freecodecamp.rocks/>。 可以採用下面的任意一種方式完成這個挑戰:
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://timestamp-microservice.freecodecamp.rocks/>。 在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- 克隆 [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-timestamp/) 並在本地完成項目。
|
||||
- 克隆 [這個 GitHub 倉庫](https://github.com/freeCodeCamp/boilerplate-project-timestamp/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-project-timestamp)來完成你的項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -8,13 +8,13 @@ dashedName: url-shortener-microservice
|
||||
|
||||
# --description--
|
||||
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://url-shortener-microservice.freecodecamp.rocks/>。 可以採用下面的任意一種方式完成這個挑戰:
|
||||
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:<https://url-shortener-microservice.freecodecamp.rocks/>。 在這個項目中,你將使用以下方法之一編寫你的代碼:
|
||||
|
||||
- 克隆 [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-filemetadata/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-project-urlshortener)來完成你的項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -18,11 +18,11 @@ dashedName: get-data-from-post-requests
|
||||
|
||||
POST(有時候是 PUT)- 使用請求發送信息,以創建新資源;
|
||||
|
||||
GET- 讀取不用修改的已存在的資源;
|
||||
GET - 讀取不用修改的已存在的資源;
|
||||
|
||||
PUT 或者 PATCH(有時候是 POST)- 發送數據,以更新資源;
|
||||
|
||||
DELETE=> 刪除一個資源。
|
||||
DELETE => 刪除一個資源。
|
||||
|
||||
還有其他兩種方法常用於與服務進行交互。 除了 GET 之外,上面列出的所有方法都可以負載數據(即數據都能放到消息正文中), 這些方法也可以使用 body-parser 中間件。
|
||||
|
||||
|
@ -10,7 +10,7 @@ dashedName: implement-a-root-level-request-logger-middleware
|
||||
|
||||
前面我們介紹了 `express.static()` 中間件函數, 現在是時候更詳細地瞭解什麼是中間件了。 中間件函數是一個接收 3 個參數的函數,這 3 個參數分別是:請求對象、響應對象和在應用的請求-響應循環中的下一個函數。 中間件函數執行一些可能對應用程序產生一些效果的代碼,通常還會在請求對象或者響應對象裏添加一些信息, 它們也可以在滿足某些條件時通過發送響應來結束循環, 如果在它們完成時沒有發送響應,那麼就會開始執行堆棧中的下一個函數, `next()` 將觸發調用第 3 個參數。
|
||||
|
||||
看看下面的例子:
|
||||
請看以下示例:
|
||||
|
||||
```js
|
||||
function(req, res, next) {
|
||||
@ -25,7 +25,7 @@ function(req, res, next) {
|
||||
|
||||
構建一個簡單的日誌記錄器。 對於每個請求,它應該在控制檯中打印一個採用以下格式的字符串:`method path - ip`, 例如:`GET /json - ::ffff:127.0.0.1`。 注意 `method` 和 `path` 之間有一個空格,並且 `path` 和 `ip` 中間的破折號的兩邊都有空格。 可以使用 `req.method`、`req.path` 和 `req.ip` 從請求對象中分別獲取請求方法(http 動詞)、路由相對路徑和請求者的 ip 信息。 當你完成時,記得要調用 `next()`,否則服務器將一直處於掛起狀態。 請確保“Logs”是打開的,觀察一下當一些請求到達時會發生什麼事情。
|
||||
|
||||
**注意:**Express 按照函數在代碼中出現的順序來執行, 中間件也是如此。 如果你想讓中間件函數適用於所有路由,那麼應該在路由之前配置好中間件。
|
||||
**注意:** Express 按照函數在代碼中出現的順序來執行, 中間件也是如此。 如果你想讓中間件函數適用於所有路由,那麼應該在路由之前配置好中間件。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -8,13 +8,13 @@ dashedName: meet-the-node-console
|
||||
|
||||
# --description--
|
||||
|
||||
可以採用下面的任意一種方式完成這些挑戰:
|
||||
你可以採用下面的任意一種編寫代碼的方式來完成這些挑戰:
|
||||
|
||||
- 克隆 [這個 GitHub 倉庫](https://github.com/freeCodeCamp/boilerplate-express/) 並在本地完成項目。
|
||||
- 使用[我們的 Repl.it 上的初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-express)來完成項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。
|
||||
|
||||
在開發過程中,能夠隨時看到代碼的運行結果是非常重要的。
|
||||
|
||||
|
@ -8,7 +8,7 @@ dashedName: add-a-version-to-your-package-json
|
||||
|
||||
# --description--
|
||||
|
||||
`version` 是 package.json 文件中必填字段之一, 這個字段描述了當前項目的版本, 如:
|
||||
`version` 是 package.json 文件中必填字段之一, 這個字段描述了當前項目的版本, 下面是一個示例:
|
||||
|
||||
```json
|
||||
"version": "1.2.0",
|
||||
|
@ -8,7 +8,7 @@ dashedName: add-keywords-to-your-package-json
|
||||
|
||||
# --description--
|
||||
|
||||
在 `keywords` 字段中可以使用相關的關鍵字描述項目。 例如:
|
||||
在 `keywords` 字段中可以使用相關的關鍵字描述項目。 下面是一個示例:
|
||||
|
||||
```json
|
||||
"keywords": [ "descriptive", "related", "words" ],
|
||||
|
@ -28,7 +28,7 @@ dashedName: expand-your-project-with-external-packages-from-npm
|
||||
|
||||
# --hints--
|
||||
|
||||
“dependencies”應該包含“moment”
|
||||
“dependencies”字段應該包含“moment”
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -8,13 +8,13 @@ dashedName: how-to-use-package-json-the-core-of-any-node-js-project-or-npm-packa
|
||||
|
||||
# --description--
|
||||
|
||||
可以採用下面的任意一種方式完成這些挑戰:
|
||||
你可以採用下面的任意一種編寫代碼的方式來完成這些挑戰:
|
||||
|
||||
- 克隆 [GitHub repo](https://github.com/freeCodeCamp/boilerplate-npm/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 上的初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-npm)來完成項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。 此外,還可以將項目的源碼提交到 `GitHub Link` 中。
|
||||
|
||||
`package.json` 文件是所有 Node.js 項目和 npm 包的樞紐, 和 HTML 文檔中的 <head> 區域用來描述網頁的配置信息(元數據)一樣,它存儲項目的相關信息。 它由單個 JSON 對象組成,並以鍵值對的形式存儲項目信息, 且至少包含兩個必填字段:“name”和“version”——但是最好提供有關項目的其他信息,這將對用戶或者維護者有所幫助。
|
||||
|
||||
|
@ -22,7 +22,7 @@ dashedName: use-the-caret-character-to-use-the-latest-minor-version-of-a-depende
|
||||
|
||||
在依賴項中,使用脫字符(`^`)爲 moment 的版本添加前綴,允許 npm 更新依賴包到任意新的次版本。
|
||||
|
||||
**注意:**原來的版本號不用更改。
|
||||
**注意:** 原來的版本號不用更改。
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -26,7 +26,7 @@ dashedName: use-the-tilde-character-to-always-use-the-latest-patch-version-of-a-
|
||||
|
||||
# --hints--
|
||||
|
||||
“dependencies”應該包含“moment”
|
||||
“dependencies”字段中應包含“moment”
|
||||
|
||||
```js
|
||||
(getUserInput) =>
|
||||
|
@ -8,7 +8,7 @@ dashedName: create-a-model
|
||||
|
||||
# --description--
|
||||
|
||||
**C**RUD 第一小節——CREATE
|
||||
**C** RUD 第一小節——CREATE
|
||||
|
||||
首先,我們需要一個 Schema, 每一個 Schema 都對應一個 MongoDB 的 collection, 並且在相應的 collection 裏定義 documents 的“樣子”。 Schema 用於組成模型(Model), 我們甚至可以通過嵌套 Schema 來創建複雜的模型。目前我們先從簡。 我們可以根據模型創建實例,模型實例化後的對象稱爲 documents。
|
||||
|
||||
|
@ -8,13 +8,13 @@ dashedName: install-and-set-up-mongoose
|
||||
|
||||
# --description--
|
||||
|
||||
可以採用下面的任意一種方式完成這些挑戰:
|
||||
你可以採用下面的任意一種編寫代碼的方式來完成這些挑戰:
|
||||
|
||||
- 克隆 [GitHub repo](https://github.com/freeCodeCamp/boilerplate-mongomongoose/) 並在本地完成項目。
|
||||
- 克隆 [這個 GitHub 倉庫](https://github.com/freeCodeCamp/boilerplate-mongomongoose/) 並在本地完成項目。
|
||||
- 使用[我們的 Replit 上的初始化項目](https://replit.com/github/freeCodeCamp/boilerplate-mongomongoose)來完成項目。
|
||||
- 使用你選擇的網站生成器來完成項目, 並確保包含了我們 GitHub 倉庫的所有文件。
|
||||
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
|
||||
|
||||
當完成本項目,請確認有一個正常運行的 demo 可以公開訪問。 然後將 URL 提交到 `Solution Link` 中。
|
||||
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 `Solution Link` 字段中提交它的 URL。
|
||||
|
||||
在這個挑戰中,你將建立一個 MongoDB Atlas 數據庫並導入連接到它所需的軟件包。
|
||||
|
||||
@ -22,7 +22,7 @@ dashedName: install-and-set-up-mongoose
|
||||
|
||||
# --instructions--
|
||||
|
||||
將 `mongodb` 和 `mongoose` 添加到項目的 `package.json` 文件中。 然後,在 `myApp.js` 文件中請求 `mongoose`。 創建一個 `.env` 文件,給它添加一個 `MONGO_URI` 變量。 變量的值爲你的 MongoDB Atlas 數據庫 URI。 應用單引號或雙引號包裹 URI。請記住,環境變量 `=` 兩邊不能有空格。 例如,`MONGO_URI='VALUE'`。 完成後,使用下面的代碼來連接數據庫。
|
||||
將 `mongodb@~3.6.0` 和 `mongoose@~5.4.0` 添加到項目的 `package.json` 中。 然後,在 `myApp.js` 文件中請求 `mongoose`。 創建一個 `.env` 文件,給它添加一個 `MONGO_URI` 變量。 變量的值爲你的 MongoDB Atlas 數據庫 URI。 應用單引號或雙引號包裹 URI。請記住,環境變量 `=` 兩邊不能有空格。 例如,`MONGO_URI='VALUE'`。 完成後,使用下面的代碼來連接數據庫。
|
||||
|
||||
```js
|
||||
mongoose.connect(<Your URI>, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||
|
Reference in New Issue
Block a user