【发布时间】:2016-03-07 15:36:24
【问题描述】:
经过多次尝试,我无法将 node.js 连接到我计算机中安装的 Neo4j。我可以分别访问两者,并且都可以正常工作。我已经在我的 Node.js 目录中安装了 Thingdom ('neo4j') 模块,但是当 require('neo4j') 打印错误时。
Image of my Node.js folder with Neo4j installed in modules
var neo4j = require("neo4j");
var db = new neo4j.GraphDatabase("http://localhost:7474");
var node = db.createNode({hello: 'world'}); // instantaneous, but...
node.save(function (err, node) { // ...this is what actually persists.
if (err) {
console.error('Error saving new node to database:', err);
} else {
console.log('Node saved to database with id:', node.id);
}
});
当在 cmd: "node index.js" 中使用时,它会抛出这个错误:
C:\Users\RRamos\Documents\Projects\test-neo4j>node index.js
module.js:341
throw err;
^
Error: Cannot find module 'neo4j'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\Users\RRamos\Documents\Projects\test-neo4j\index.js:1:75)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
【问题讨论】:
-
看起来好像模块是作为全局安装的,这不好。为项目在本地安装。
-
我认为是安装在项目内部。您可以在图像中查看它(我的 Node.js 文件夹的图像,其中 Neo4j 安装在模块中)。
-
没错!我明白了!,现在看来它可以工作了
-
我遇到了同样的问题,我在
web/目录下安装了neo4j-driver,但它应该更高一级,与我的node.js服务器代码在同一目录中。
标签: javascript node.js neo4j