Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find module 'passport-local' error

am using passport in node.js

in my app.js

var passport = require('passport')

require('./config/passport').boot(passport, config)

in passport.js

var LocalStrategy = require('passport-local').Strategy

run the app and i get this error message

module.js:340
    throw err;

error:Cannot find module 'passport-local'
      at Object.<anonymous> <F:\work\config\passport.js:2:21>

i install the passport in F:\work\node_modules.

even if i put the

 var LocalStrategy = require('passport-local').Strategy

right under the

 var passport = require('passport')

i still get the same error

any idea why?

like image 971
paynestrike Avatar asked Oct 11 '12 04:10

paynestrike


People also ask

What is NPM passport local?

Passport-Local Mongoose is a Mongoose plugin that simplifies building username and password login with Passport.

How to reset password in passport js?

You can reset or change passwords using 2 simple functions in passport-local-mongoose. They are setPassword function and changePassword functions. Normally setPassword is used when the user forgot the password and changePassword is used when the user wants to change the password.

How to change password in mongoose?

No need to authenticate. Retrieve user from account using findByUsername() method, which was placed on the model by passport-local-mongoose, then run setPassword() , then user. save() in the callback.


1 Answers

I had the same problem and I solved it:

Check your package.json file. If it does not exist, you need to init your project in the same folder where you wrote your main JS file (server.js or index.js or however you want).

$ sudo npm init 

and when installing npm modules, remeber to save them in package file:

$ sudo npm install passport-local --save 

I solved in this way.

like image 113
Milani Igor Avatar answered Oct 02 '22 04:10

Milani Igor