将Neo4j连接至Node.js时出现错误,请求技术排查解决
Hey there! Let's fix those two issues you're hitting with your Neo4j + JavaScript setup:
1. Resolve the body-parser Deprecation Warning
That warning pops up because you haven't explicitly set the extended option for body-parser.urlencoded(). Modern versions of body-parser (and Express, which includes it natively now) require this to be defined.
Here's how to fix it:
- If you're using the standalone
body-parserpackage:const bodyParser = require('body-parser'); // Replace your existing urlencoded middleware with this app.use(bodyParser.urlencoded({ extended: true })); // Use `false` instead if you only need to parse strings/arrays, not nested objects - If you're on Express 4.16 or later, you can skip the separate
body-parserpackage entirely and use Express's built-in parser:app.use(express.urlencoded({ extended: true }));
2. Fix the Neo4j Connection Failure (getaddrinfo ENOTFOUND locthost)
This one's a simple typo! You've spelled localhost as locthost (missing an 'a') in your Neo4j connection string.
Find where you initialize the Neo4j driver in your code— it'll look something like this:
const driver = neo4j.driver('bolt://locthost:7687', neo4j.auth.basic('your-username', 'your-password'));
Just correct the hostname to localhost:
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('your-username', 'your-password'));
Double-check that your Neo4j server is running locally on port 7687 (the default Bolt port) and this connection error should disappear.
内容的提问来源于stack exchange,提问作者Nicole Marie

