gol*_*t25 8 session-cookies express
我需要你的帮助来使用express构建rest API。我已经尝试了很多版本的express。也有 CookieParser 中间件,但我刚刚收到上述错误......
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)`
Run Code Online (Sandbox Code Playgroud)
我全局安装了 cookie 解析器并使用 Express 版本 4....代码片段如下。
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();
Run Code Online (Sandbox Code Playgroud)
app.use(session({ Secret: 'angcms', saveUninitialized: true, resave: true })); app.use(cookieParser());
小智 10
我也有同样的情况。我是这样解决的:
$ npm install
Run Code Online (Sandbox Code Playgroud)
您必须在项目文件夹中键入此内容。如果我理解的话,“npm install”会检查在 JSON 文件上注册的项目依赖项。
听起来 npm 已经搞砸了你的模块安装了。尝试完全重新安装此模块。
卸载完整模块
$ npm uninstall cookie-parser
Run Code Online (Sandbox Code Playgroud)
卸载模块后,使用以下命令再次安装
$ npm install cookie-parser -g
Run Code Online (Sandbox Code Playgroud)
注意:如果您之前没有安装过,请先安装并执行。
| 归档时间: |
|
| 查看次数: |
42877 次 |
| 最近记录: |