mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-03 10:01:47 -04:00
fix: update Basic Node and Express challenge text (#47048)
* fix: update body-parser text * fix: update dotenv text * Update curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-body-parser-to-parse-post-requests.md Co-authored-by: Sem Bauke <semboot699@gmail.com> * Update curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md Co-authored-by: Ilenia <nethleen@gmail.com> * Update curriculum/challenges/english/05-back-end-development-and-apis/basic-node-and-express/use-body-parser-to-parse-post-requests.md Co-authored-by: Sem Bauke <semboot699@gmail.com> Co-authored-by: Sem Bauke <semboot699@gmail.com> Co-authored-by: Ilenia <nethleen@gmail.com>
This commit is contained in:
committed by
GitHub
parent
5cfa9caa61
commit
9bcd2d778a
@@ -22,11 +22,11 @@ Content-Length: 20
|
||||
name=John+Doe&age=25
|
||||
```
|
||||
|
||||
As you can see, the body is encoded like the query string. This is the default format used by HTML forms. With Ajax, you can also use JSON to handle data having a more complex structure. There is also another type of encoding: multipart/form-data. This one is used to upload binary files. In this exercise, you will use a urlencoded body. To parse the data coming from POST requests, you have to install the `body-parser` package. This package allows you to use a series of middleware, which can decode data in different formats.
|
||||
As you can see, the body is encoded like the query string. This is the default format used by HTML forms. With Ajax, you can also use JSON to handle data having a more complex structure. There is also another type of encoding: multipart/form-data. This one is used to upload binary files. In this exercise, you will use a URL encoded body. To parse the data coming from POST requests, you must use the `body-parser` package. This package allows you to use a series of middleware, which can decode data in different formats.
|
||||
|
||||
# --instructions--
|
||||
|
||||
Install the `body-parser` module in your `package.json`. Then, `require` it at the top of the file. Store it in a variable named `bodyParser`. The middleware to handle urlencoded data is returned by `bodyParser.urlencoded({extended: false})`. Pass the function returned by the previous method call to `app.use()`. As usual, the middleware must be mounted before all the routes that depend on it.
|
||||
`body-parser` has already been installed and is in your project's `package.json` file. `require` it at the top of the `myApp.js` file and store it in a variable named `bodyParser`. The middleware to handle URL encoded data is returned by `bodyParser.urlencoded({extended: false})`. Pass the function returned by the previous method call to `app.use()`. As usual, the middleware must be mounted before all the routes that depend on it.
|
||||
|
||||
**Note:** `extended` is a configuration option that tells `body-parser` which parsing needs to be used. When `extended=false` it uses the classic encoding `querystring` library. When `extended=true` it uses `qs` library for parsing.
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ Then, in the `/json` GET route handler you created in the last challenge access
|
||||
|
||||
**Note:** If you are using Replit, you cannot create a `.env` file. Instead, use the built-in <dfn>SECRETS</dfn> tab to add the variable.
|
||||
|
||||
If you are working locally, you will need the `dotenv` package. It loads environment variables from your `.env` file into `process.env`. Install it with `npm install dotenv`. Then, at the top of your `myApp.js` file, import and load the variables with `require('dotenv').config()`.
|
||||
If you are working locally, you will need the `dotenv` package. It loads environment variables from your `.env` file into `process.env`. The `dotenv` package has already been installed, and is in your project's `package.json` file. At the top of your `myApp.js` file, import and load the variables with `require('dotenv').config()`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user