Last modified: Jun 23, 2026
Fix express-validator Module Not Found
You are building a Node.js app with Express. You install express-validator. But when you run the server, you see this:
Error: Cannot find module 'express-validator'
Require stack:
- /home/user/project/app.js
This error stops your app. It is common for beginners. But it is easy to fix. This article shows you why it happens and how to solve it.
Why Does This Error Happen?
The error means Node.js cannot locate the express-validator package. The most common reasons are:
- You forgot to install the package.
- You installed it in the wrong directory.
- Your
node_modulesfolder is missing or corrupted. - You have a typo in the package name.
- You are using a different Node version.
Let's fix each one step by step.
Step 1: Install express-validator
The first thing to check is installation. Open your terminal in the project root. Run this command:
npm install express-validator
This adds the package to node_modules and updates package.json. After installation, try running your app again.
If you use yarn, run:
yarn add express-validator
Always install packages in your project folder. Do not install globally for local projects.
Step 2: Check Your Working Directory
Sometimes you run the command in the wrong folder. Your terminal must be inside the project where package.json lives. Use pwd (Mac/Linux) or cd to verify.
Example:
cd /home/user/my-express-app
npm install express-validator
If you install it in a subfolder, Node.js cannot find it when you require it from the main file.
Step 3: Verify Package.json
Open your package.json file. Look for express-validator inside dependencies. It should look like this:
{
"dependencies": {
"express-validator": "^7.0.1"
}
}
If the package is missing from package.json, run npm install express-validator --save. The --save flag ensures it is recorded.
Step 4: Delete node_modules and Reinstall
A corrupted node_modules folder can cause this error. Delete it and reinstall all packages.
Run these commands:
rm -rf node_modules
npm install
This gives you a fresh start. After this, test your app again.
Step 5: Check for Typos in Your Code
Double-check your require statement. It must match exactly: require('express-validator'). Common mistakes include:
- Using
express-validatorwith a capital letter. - Adding extra spaces like
require('express-validator '). - Using a hyphen instead of underscore or vice versa.
Correct example:
const { body, validationResult } = require('express-validator');
If you see this error, check your import line first.
Step 6: Clear npm Cache
Sometimes npm cache causes issues. Clear it and reinstall.
npm cache clean --force
npm install express-validator
This forces npm to download the package fresh.
Step 7: Use the Correct Node Version
Some packages need specific Node.js versions. Check your Node version:
node -v
express-validator works with Node 10 and above. If you use an older version, upgrade Node. You can use nvm (Node Version Manager) to switch versions easily.
Example: Full Working Setup
Let's build a simple app to test everything works.
First, create a new project:
mkdir test-validator
cd test-validator
npm init -y
npm install express express-validator
Create app.js with this code:
const express = require('express');
const { body, validationResult } = require('express-validator');
const app = express();
app.use(express.json());
app.post('/user',
body('email').isEmail(),
(req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
res.send('User is valid');
}
);
app.listen(3000, () => console.log('Server running on port 3000'));
Now run the server:
node app.js
You should see "Server running on port 3000". Test it with curl:
curl -X POST http://localhost:3000/user -H "Content-Type: application/json" -d '{"email":"test@example.com"}'
Output:
User is valid
If you get the error again, go back through the steps above.
Related Error: Cannot find module
This error is similar to other Node.js module errors. If you see Cannot find module 'some-package', the same steps apply. For a general guide, check our article on Fix Node.js Error: Cannot find module. It covers common packages and solutions.
Prevent This Error in the Future
Here are some tips to avoid this error:
- Always run
npm installafter cloning a project. - Use a
.gitignorefile to excludenode_modules. - Keep your
package.jsonandpackage-lock.jsonin version control. - Check the official
express-validatordocumentation for updates.
Conclusion
The Cannot find module 'express-validator' error is easy to fix. Start by installing the package. Check your working directory. Verify package.json. Delete and reinstall node_modules if needed. Look for typos in your code. Clear npm cache. And ensure you use a compatible Node version.
With these steps, your Express app will run smoothly. Remember to test with a simple example first. For more help, see our guide on Fix Node.js Error: Cannot find module. Happy coding!