1 | # Version 3 to Version 4 Upgrade Guide
|
2 | Version 4 came with lots of hotness, but as a major version, this usually implies
|
3 | some breaking changes were made and therefore your app may not work properly as it used to.
|
4 |
|
5 | **Don't worry, most of the version 2/3 APIs are still here**.
|
6 | We haven't really removed anything, we only added new APIs that are easier to use and extend in the future.
|
7 | You don't need to migrate to the new APIs if you don't want to, although we recommend you to do so as soon as possible.
|
8 |
|
9 | ## Breaking changes
|
10 | ### Node v6+ support only
|
11 | Node v0.10+, previously supported by express-validator v3, is no longer supported.
|
12 | You must update to Node v6 or newer in order to use express-validator v4+.
|
13 |
|
14 | ### Bluebird is no longer a dependency
|
15 | In case your code relied on Bluebird promise extensions, you should migrate them to plain JS promises,
|
16 | as this is the used implementation now.
|
17 |
|
18 | ### Validators execution time
|
19 | Previously, validators were run in an eager manner.
|
20 | This meant that the following would run the validations right away:
|
21 |
|
22 | ```js
|
23 | req.check('email').isEmail();
|
24 | ```
|
25 |
|
26 | In v4+, the validators are lazily run in the legacy API.
|
27 | You must call one of the methods to retrieve the validation errors in order for them to execute:
|
28 |
|
29 | - `req.validationErrors()`
|
30 | - `req.asyncValidationErrors()`
|
31 | - `req.getValidationResult()`
|
32 |
|
33 | ### Usage of `req.validationErrors(true)`/`req.asyncValidationErrors(true)`
|
34 | Previously in v3-, mapped validation errors (the result of invoking `req.validationErrors(true)`/`req.asyncValidationErrors(true)`)
|
35 | would return an object with the *last* error for each invalid field.
|
36 |
|
37 | The new behaviour is to always return the *first* error.
|
38 |
|
39 | ### Validation Result API changes
|
40 | The validation result API (the object that `req.getValidationResult()` returns after its promise resolves)
|
41 | no longer provides a method called `.useFirstErrorOnly()`.
|
42 |
|
43 | Usages of `.mapped()` will always return only the first error, and usages of `.array()` may be configured
|
44 | to return only the first error for each field by passing `{ onlyFirstError: true }` as an argument.
|