【问题标题】:how to use connect-orientdb module with express如何在 express 中使用 connect-orientdb 模块
【发布时间】:2016-11-07 08:50:30
【问题描述】:

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

执行 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 是一个不同的模块,我遇到了这个问题。

【问题讨论】:

  • 似乎您的具有“商店”属性的值之一未定义。
  • @OleksandrGubchenko 是的,这就是问题所在,但我检查了其他数据库,例如 mongoDB,他们使用了这种方法,并且没有这个问题。 store 属性在 connect-mongodb 模块中定义。

标签: javascript node.js express orientdb nosql


【解决方案1】:

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

还有try to use

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

代替:

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

【讨论】:

  • orient 是一个不同的模块,我使用这个 link : npmjs.com 来使用 connect-orientdb 模块,但是现在会话模块不是 expressjs 中的内置模块,我已经单独需要它了.
  • 我的主要问题是在 express 中内置 session 模块时使用了 connect-orientdb,但现在该 session 是一个不同的模块,我遇到了这个问题。
  • 不是官方模块,可能已经过时了
【解决方案2】:

如果有人遇到这个问题,我终于找到了解决方案:

var session = require('express-session'),
    OrientoStore = require('connect-oriento')(session);

app.use(session({
        secret: 'SomeSecret',
        store: new OrientoStore({
            server: "host=localhost&port=2424&username=dev&password=dev&db=test"
        })
    }));

有关更多信息,此github link 很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 2020-10-25
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2023-03-17
    • 2018-06-17
    相关资源
    最近更新 更多