javascript - 如何在 express 中使用 connect-orientdb 模块

标签 javascript node.js express orientdb nosql

我的目标是将带有 nodejs 和 expressjs 框架的服务器代码连接到带有 orientdb 的数据库。 首先,我想将我的 session 存储在数据库中。但是我很难将我的服务器连接到数据库。

执行 server.js 时出现的错误:

  /Users/soroush/Desktop/nodeOrient/node_modules/connect-orientdb/lib/connect-orientdb.coffee:191
    })(connect.session.Store);
                      ^

TypeError: Cannot read property 'Store' of undefined
  at module.exports (/Users/soroush/Desktop/nodeOrient/node_modules/connect-orientdb/lib/connect-orientdb.coffee:22:46)
  at Object.<anonymous> (/Users/soroush/Desktop/nodeOrient/server.js:8:48)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (module.js:458:32)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Function.Module.runMain (module.js:575:10)
  at startup (node.js:160:18)
  at node.js:449:3

我的 server.js 代码是:

var express = require('express'),
    cs = require("coffee-script/register"),
    app = express(),
    path = require('path'),
    cookieParser = require('cookie-parser'),
    session = require('express-session'),
    config = require('./config/config.js'),
    orientDBStore = require('connect-orientdb')(session),
    OrientDB = require('orientjs'),
    orientDBConfig = {
        server : {
            host: "localhost",
            port:2424
        },
        db : {
            user_name: "admin",
            user_password: "admin"
        },
        database : "sessions",
        class_name : "sessions_class"
    },
    server  = OrientDB({
    hose : "localhost",
    port : "2424",
    username : "root",
    password : "root"
    })
    ;

app.set('views', path.join(__dirname, 'views'));
app.engine('html', require('hogan-express'));
app.set('view engine', 'html');
app.use(express.static(path.join(__dirname,'public' )));

app.use(cookieParser());

require('./routes/route.js')(express, app);

    app.use(session({
        secret:"mySecret",
        store: new orientDBStore(orientDBConfig)
    }));

app.listen(8000, function () {
    console.log("app is listening on port 8000");
})

我的主要问题是在 express 中内置 session 模块时使用了 connect-orientdb,但现在 session 是一个不同的模块,我想到了这个问题。

最佳答案

查看 OrientDB 中 ExpressJS 的指南:Blog Tutorial with ExpressJS and OrientDB .

try to use :

orientDBStore = require('orient')(session),

代替:

orientDBStore = require('connect-orientdb')(session),

关于javascript - 如何在 express 中使用 connect-orientdb 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40461076/

相关文章:

javascript - 导航栏 - 使用 JavaScript 切换事件链接

javascript - 每个新单词瑞典语字符和 html 标记均大写

javascript - 如何获取匹配子项的 Firebase 快照?

mysql - NodeJS mysql 获取相关数据

javascript - JQuery 嵌套列表过滤器 - 当父级匹配时显示所有子级

javascript - 如何让 Node.js 等待来自大请求的响应

node.js - 将 Node 与 Jade/Stylus 一起使用时的最佳 "GUI"IDE

node.js - 使用 request(),返回的页面还不包含需要的数据——而是返回不完整的页面。我如何 'wait' ?

Express.JS 获取 url 路径,无需任何附加参数

javascript - Mongoose - $并且无法正常运行,需要找到包含这两个项目的数组