Skip to content

Commit c362513

Browse files
committed
Deploy website
Deploy website version based on b9be25deb4cfcbd27e6a70bbd524f945b1d250b1
1 parent 3b35511 commit c362513

38 files changed

Lines changed: 2280 additions & 253 deletions

docs/6.9.2/check-api.html

Lines changed: 161 additions & 0 deletions
Large diffs are not rendered by default.

docs/6.9.2/custom-error-messages.html

Lines changed: 159 additions & 0 deletions
Large diffs are not rendered by default.

docs/6.9.2/custom-validators-sanitizers.html

Lines changed: 123 additions & 0 deletions
Large diffs are not rendered by default.

docs/6.9.2/filter-api.html

Lines changed: 124 additions & 0 deletions
Large diffs are not rendered by default.

docs/6.9.2/index.html

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Getting Started · express-validator</title><meta name="viewport" content="width=device-width"/><meta name="generator" content="Docusaurus"/><meta name="description" content="express-validator is a set of [express.js](http://expressjs.com/) middlewares that wraps"/><meta name="docsearch:version" content="6.9.2"/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Getting Started · express-validator"/><meta property="og:type" content="website"/><meta property="og:url" content="https://express-validator.github.io/index.html"/><meta property="og:description" content="express-validator is a set of [express.js](http://expressjs.com/) middlewares that wraps"/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/img/favicon.png"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script src="/js/scrollSpy.js"></script><link rel="stylesheet" href="/css/main.css"/><script src="/js/codetabs.js"></script></head><body class="sideNavVisible separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/"><img class="logo" src="/img/logo.svg" alt="express-validator"/><h2 class="headerTitleWithLogo">express-validator</h2></a><a href="/versions.html"><h3>6.9.2</h3></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class="siteNavGroupActive siteNavItemActive"><a href="/docs/6.9.2/index.html" target="_self">Docs</a></li><li class="siteNavGroupActive"><a href="/docs/6.9.2/check-api.html" target="_self">API</a></li><li class=""><a href="https://github.com/express-validator/express-validator" target="_self">GitHub</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><div class="hamburger-menu"><div class="line1"></div><div class="line2"></div><div class="line3"></div></div></div><h2><i></i><span>Introduction</span></h2><div class="tocToggler" id="tocToggler"><i class="icon-toc"></i></div></div><div class="navGroups"><div class="navGroup"><h3 class="navGroupCategoryTitle">Introduction</h3><ul class=""><li class="navListItem navListItemActive"><a class="navItem" href="/docs/6.9.2/index.html">Getting Started</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Features</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/6.9.2/sanitization.html">Sanitization</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/custom-validators-sanitizers.html">Custom validators/sanitizers</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/custom-error-messages.html">Custom Error Messages</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/wildcards.html">Wildcards</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/schema-validation.html">Schema Validation</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/whole-body-validation.html">Whole Body Validation</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/running-imperatively.html">Running validations imperatively</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">API</h3><ul class=""><li class="navListItem"><a class="navItem" href="/docs/6.9.2/check-api.html">Validation middlewares</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/validation-chain-api.html">Validation Chain API</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/filter-api.html">Sanitization middlewares</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/sanitization-chain-api.html">Sanitization Chain API</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/matched-data-api.html">matchedData()</a></li><li class="navListItem"><a class="navItem" href="/docs/6.9.2/validation-result-api.html">validationResult()</a></li></ul></div></div></section></div><script>
2+
var coll = document.getElementsByClassName('collapsible');
3+
var checkActiveCategory = true;
4+
for (var i = 0; i < coll.length; i++) {
5+
var links = coll[i].nextElementSibling.getElementsByTagName('*');
6+
if (checkActiveCategory){
7+
for (var j = 0; j < links.length; j++) {
8+
if (links[j].classList.contains('navListItemActive')){
9+
coll[i].nextElementSibling.classList.toggle('hide');
10+
coll[i].childNodes[1].classList.toggle('rotate');
11+
checkActiveCategory = false;
12+
break;
13+
}
14+
}
15+
}
16+
17+
coll[i].addEventListener('click', function() {
18+
var arrow = this.childNodes[1];
19+
arrow.classList.toggle('rotate');
20+
var content = this.nextElementSibling;
21+
content.classList.toggle('hide');
22+
});
23+
}
24+
25+
document.addEventListener('DOMContentLoaded', function() {
26+
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
27+
createToggler('#tocToggler', 'body', 'tocActive');
28+
29+
var headings = document.querySelector('.toc-headings');
30+
headings && headings.addEventListener('click', function(event) {
31+
var el = event.target;
32+
while(el !== headings){
33+
if (el.tagName === 'A') {
34+
document.body.classList.remove('tocActive');
35+
break;
36+
} else{
37+
el = el.parentNode;
38+
}
39+
}
40+
}, false);
41+
42+
function createToggler(togglerSelector, targetSelector, className) {
43+
var toggler = document.querySelector(togglerSelector);
44+
var target = document.querySelector(targetSelector);
45+
46+
if (!toggler) {
47+
return;
48+
}
49+
50+
toggler.onclick = function(event) {
51+
event.preventDefault();
52+
53+
target.classList.toggle(className);
54+
};
55+
}
56+
});
57+
</script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/express-validator/express-validator/edit/master/docs/index.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">Getting Started</h1></header><article><div><span><p>express-validator is a set of <a href="http://expressjs.com/">express.js</a> middlewares that wraps
58+
<a href="https://github.com/chriso/validator.js">validator.js</a> validator and sanitizer functions.</p>
59+
<h2><a class="anchor" aria-hidden="true" id="installation"></a><a href="#installation" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Installation</h2>
60+
<p>Install it using npm (make sure that you have Node.js 8 or newer):</p>
61+
<pre><code class="hljs">npm install --<span class="hljs-built_in">save</span> <span class="hljs-built_in">express</span>-validator
62+
</code></pre>
63+
<h2><a class="anchor" aria-hidden="true" id="basic-guide"></a><a href="#basic-guide" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Basic guide</h2>
64+
<blockquote>
65+
<p>It's recommended that you have basic knowledge of the express.js module before you go on with
66+
this guide.</p>
67+
</blockquote>
68+
<p>Let's get started by writing a basic route to create a user in the database:</p>
69+
<pre><code class="hljs css language-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
70+
<span class="hljs-keyword">const</span> app = express();
71+
72+
app.use(express.json());
73+
app.post(<span class="hljs-string">'/user'</span>, (req, res) =&gt; {
74+
User.create({
75+
<span class="hljs-attr">username</span>: req.body.username,
76+
<span class="hljs-attr">password</span>: req.body.password,
77+
}).then(<span class="hljs-function"><span class="hljs-params">user</span> =&gt;</span> res.json(user));
78+
});
79+
</code></pre>
80+
<p>Then, you'll want to make sure that you validate the input and report any errors before creating the user:</p>
81+
<pre><code class="hljs css language-js"><span class="hljs-comment">// ...rest of the initial code omitted for simplicity.</span>
82+
<span class="hljs-keyword">const</span> { body, validationResult } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express-validator'</span>);
83+
84+
app.post(
85+
<span class="hljs-string">'/user'</span>,
86+
<span class="hljs-comment">// username must be an email</span>
87+
body(<span class="hljs-string">'username'</span>).isEmail(),
88+
<span class="hljs-comment">// password must be at least 5 chars long</span>
89+
body(<span class="hljs-string">'password'</span>).isLength({ <span class="hljs-attr">min</span>: <span class="hljs-number">5</span> }),
90+
(req, res) =&gt; {
91+
<span class="hljs-comment">// Finds the validation errors in this request and wraps them in an object with handy functions</span>
92+
<span class="hljs-keyword">const</span> errors = validationResult(req);
93+
<span class="hljs-keyword">if</span> (!errors.isEmpty()) {
94+
<span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).json({ <span class="hljs-attr">errors</span>: errors.array() });
95+
}
96+
97+
User.create({
98+
<span class="hljs-attr">username</span>: req.body.username,
99+
<span class="hljs-attr">password</span>: req.body.password,
100+
}).then(<span class="hljs-function"><span class="hljs-params">user</span> =&gt;</span> res.json(user));
101+
},
102+
);
103+
</code></pre>
104+
<p><em>Voila!</em> Now, whenever a request that includes invalid <code>username</code> or <code>password</code> fields
105+
is submitted, your server will respond like this:</p>
106+
<pre><code class="hljs css language-json">{
107+
<span class="hljs-attr">"errors"</span>: [
108+
{
109+
<span class="hljs-attr">"location"</span>: <span class="hljs-string">"body"</span>,
110+
<span class="hljs-attr">"msg"</span>: <span class="hljs-string">"Invalid value"</span>,
111+
<span class="hljs-attr">"param"</span>: <span class="hljs-string">"username"</span>
112+
}
113+
]
114+
}
115+
</code></pre>
116+
<p>For all the available validators in express-validator (just like its options),
117+
take a look at validator.js docs <a href="https://github.com/chriso/validator.js#validators">here</a>.</p>
118+
<h2><a class="anchor" aria-hidden="true" id="whats-next"></a><a href="#whats-next" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>What's next</h2>
119+
<p>This completes the basic guide on getting started with express-validator.<br>
120+
You might want to continue reading about some of the more advanced features available:</p>
121+
<ul>
122+
<li><a href="/docs/6.9.2/sanitization.html">Sanitization</a></li>
123+
<li><a href="/docs/6.9.2/custom-validators-sanitizers.html">Custom validators/sanitizers</a></li>
124+
<li><a href="/docs/6.9.2/custom-error-messages.html">Custom error messages</a></li>
125+
<li><a href="/docs/6.9.2/wildcards.html">Wildcards</a></li>
126+
<li><a href="/docs/6.9.2/schema-validation.html">Schema validation</a></li>
127+
</ul>
128+
</span></div></article></div><div class="docs-prevnext"><a class="docs-next button" href="/docs/6.9.2/sanitization.html"><span>Sanitization</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#installation">Installation</a></li><li><a href="#basic-guide">Basic guide</a></li><li><a href="#whats-next">What's next</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/logo.svg" alt="express-validator" width="66" height="58"/></a><div><h5>Docs</h5><a href="/docs/index.html">Getting Started</a><a href="/docs/check-api.html">API Reference</a></div><div><h5>Community</h5><a href="http://stackoverflow.com/questions/tagged/express-validator" target="_blank" rel="noreferrer noopener">Stack Overflow</a></div><div><h5>More</h5><a href="https://github.com/express-validator/express-validator">GitHub</a><a class="github-button" href="https://github.com/express-validator/express-validator" data-icon="octicon-star" data-count-href="/express-validator/express-validator/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2021 express-validator</section></footer></div></body></html>

0 commit comments

Comments
 (0)