Reputation: 140
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());
Upvotes: 8
Views: 47526
Reputation: 653
I have had the issue and I am not sure what the reason was but what fixed it for me was to go in node_modules/cookie-parser
and look at the package.json
inside it.
I then installed the dependancies listed there and it solved the problem.
(Those dependancies were cookie
and cookie-signature
)
Upvotes: 0
Reputation: 3893
I had the same problem in Azure, no one of the solutions above worked. This one solved my problem:
npm i yarn -g
yarn add cookie-parser
Upvotes: 1
Reputation: 67
To solve this problem, create another project and install cookie or open other project that have cookie installed and open node_module
and copy the folder cookie and replace it.
This problem happens because you have npm
and yarn
installed
if you open the node module folder, the cookie folder is empty
because yarn or npm
did not install the package
Upvotes: 2
Reputation: 99
You haven't install the typescript define of cookie-parser module, install @types/cookie-parser
to solve it.
$ npm install @types/cookie-parser -D
Upvotes: 4
Reputation: 508
It sounds like npm has screwed up your module installation is all. Try reinstalling this module completely.
Uninstalling complete module
$ npm uninstall cookie-parser
after uninstalling the module, install it again using below command
$ npm install cookie-parser -g
Note: if you have not installed before then install first and the execute .
Upvotes: 8
Reputation: 101
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.
Upvotes: 10