title: How to make sure the field is must have using optional in express-validator?
body: <p>I cannot fully understand the doc</p>
  <p><a href="https://express-validator.github.io/docs/validation-chain-api.html" rel="nofollow noreferrer">https://express-validator.github.io/docs/validation-chain-api.html</a>
  By default, fields with undefined values will be ignored from the validation.</p>
  <p>You can customize this behavior by passing an object with the following options:</p>
  <p>nullable: if true, fields with null values will be considered optional</p>
  <p>checkFalsy: if true, fields with falsy values (eg &quot;&quot;, 0, false, null) will also be considered optional</p>
  <p>My pseudo code is like this, basically we want to have a common validator, but sometimes the body field is optional.</p>
  <pre><code>...
  const { body, validationResult } = require('express-validator');
  
  
  const myValidator = (v, isOptional) =&gt; {
      return body(v).optional({nullable: isOptional}).isNumeric();
      // more validations will be added here
  }
  
  app.post('/info',
      myValidator('value1', false), // must have value1
      myValidator('value2', true),  // might have value2
      (req, res) =&gt; {
          res.status(200).json({
              success: true,
              message: 'success',
          })
      });
  ...
  </code></pre>
  <p>shall i use nullable or checkFalsy in the parameter for optional() ?</p>