Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find module 'cookie' while using the express module

I need your help on building rest API using express.. I have tried many versions of express. that also have CookieParser middleware but I'm just getting the above error...

  Error: Cannot find module 'cookie'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)`

I installed the cookie-parser globally and using Express version 4.... the code snippet is below.

var express = require('express'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
session = require('express-session'),
mongoose = require('mongoose'),
api = require('./routes/api.js') ,  
app = express();

app.use(session({ secret: 'angcms', saveUninitialized: true, resave: true })); app.use(cookieParser());

like image 936
goldsoft25 Avatar asked Jun 06 '26 17:06

goldsoft25


1 Answers

I had the same situation. I solved by this way:

$ npm install

You must type this inside the Project folder. If i understood, "npm install" check the project dependencies registered on JSON files.

like image 172
Mr. Junckes Avatar answered Jun 10 '26 05:06

Mr. Junckes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!