You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将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-parser package:
    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-parser package 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:30:41