使用快速模块时找不到模块"cookie" [英] cannot find module 'cookie' while using the express module

查看:289
本文介绍了使用快速模块时找不到模块"cookie"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用express构建REST API时,我需要您的帮助.我尝试了许多版本的express.那里也有CookieParser中间件,但是我只是遇到了上面的错误...

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)`

我全局安装了cookie解析器,并使用Express版本4....下面是代码段.

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({ 秘密:"angcms", saveUninitialized:是的, resave:true})); app.use(cookieParser());

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

推荐答案

听起来npm搞砸了模块安装的全部过程.尝试完全重新安装此模块.

It sounds like npm has screwed up your module installation is all. Try reinstalling this module completely.

卸载完整的模块

$ 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 .

这篇关于使用快速模块时找不到模块"cookie"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆