I am new to nodejs. I got one nodejs application and i was just trying to run the tests this app contains. So i tried to run npm test command after installing all packages using npm install. But npm test is throwing below error always
internal/modules/cjs/loader.js:657
    throw err;
    ^
Error: Cannot find module 'supertest'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:655:15)
    at Function.Module._load (internal/modules/cjs/loader.js:580:25)
    at Module.require (internal/modules/cjs/loader.js:711:19)
    at require (internal/modules/cjs/helpers.js:14:16)
I tried to uninstall and install supertest but it did not help. I see there is no node_modules folder inside supertest. Would that be an issue? How do we fix it?
Here is the file which is using supertest
var fs = require('fs')
var request = require('supertest')
var config = require('./config').getConfig()
var url = config.url
var caCert
if (config.caCertFile) {
  caCert = fs.readFileSync(config.caCertFile)
}
var preparedRequest = function () {
  return caCert ? request.agent(url, { ca: caCert }) : request(url)
}
module.exports = preparedRequest
                It seems that supertest is not in your package.json depencendies. So If you run npm install, it will not install supertest.
Just run npm install supertest to install supertest, or npm install --save supertest to install it and add the dependency in your package.json so the next time you run npm install it will install supertest too :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With