UNPKG

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