Troubleshooting Typesense Connection Refused Error on Express.js
TLDR anuser was getting an "ECONNREFUSED" error when using Typesense with Express.js. Kishore Nallan and Yoann helped identify the issue as an IPV6 compatibility conflict. Changing 'localhost' to '127.0.0.1' resolved the issue.
Jul 06, 2023 (5 months ago)
anuser
12:21 PMi try using typesens on express js but when i hit the endpoint it get an error
the error look like this
Request #1688645331733: Request to Node 0 failed due to "ECONNREFUSED connect ECONNREFUSED ::1:8108"
Request #1688645331733: Sleeping for 0.1s and then retrying request...
Request #1688645331733: Request to Node 0 failed due to "ECONNREFUSED connect ECONNREFUSED ::1:8108"
Request #1688645331733: Sleeping for 0.1s and then retrying request...```
my code looks like thisconst express = require("express");
const Typesense = require("typesense");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const port = 3000;
const typesenseClient = new Typesense.Client({
nodes: [
{
host: "localhost",
port: "8108",
protocol: "http",
},
],
apiKey: "xyz",
connectionTimeoutSeconds: 2,
});
app.use(express.json());
app.post("/data", async (req, res) => {
try {
const newData = req.body;
const createdDocument = await typesenseClient
.collections("data")
.documents()
.create(newData);
res.json(createdDocument);
} catch (error) {
console.error("Error creating data:", error);
res.status(500).json({ error: "Internal server error" });
}
});
app.listen(port, () => {
console.log(
running on <http://localhost>:${port}
);});
btw i already install the typesense on my machine using brew
brew install typesense/tap/[email protected]brew services start [email protected]
typsense.ini looks like this api-address = 0.0.0.0
api-port = 8108
api-key = xyz
data-dir = /opt/homebrew/var/lib/typesense
log-dir = /opt/homebrew/var/log/typesense
enable-cors = true```
Kishore Nallan
12:23 PM<http://localhost:8108/health>
in the browser?anuser
12:24 PM}
Kishore Nallan
12:29 PMconnectionTimeoutSeconds: 2,
and if that does not help, check Typesense logs to see whether any error is loggedanuser
01:04 PMcurl "${TYPESENSE_HOST}/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
"name": "books",
"fields": [
{"name": "title", "type": "string" },
{"name": "authors", "type": "string[]", "facet": true },
{"name": "publication_year", "type": "int32", "facet": true },
{"name": "ratings_count", "type": "int32" },
{"name": "average_rating", "type": "float" }
],
"default_sorting_field": "ratings_count"
}'
Kishore Nallan
01:05 PManuser
01:05 PMKishore Nallan
01:07 PMRequest to Node 0 failed due to "ECONNREFUSED connect ECONNREFUSED ::1:8108"
The
::1:
part looks weird to me. It's trying to connect via IPV6 address?Yoann
01:18 PMlocalhost
to 127.0.0.1
Kishore Nallan
01:19 PManuser
01:45 PMTypesense
Indexed 3011 threads (79% resolved)
Similar Threads
Typesense Search Functionality Issue on CentOS Client Server
Shabber is facing an issue with Typesense search functionality on a CentOS client server. The curl request works, but not from JS. The issue remains unresolved, and Shabber will request the public IP of the server and enable port 8108.
Connection Refused Issue with Typesense and Nginx Reverse Proxy
Karthik experiences a connection refused problem with Typesense and Nginx reverse proxy. Jason helps troubleshoot, but the issue remains unresolved.
Troubleshooting Typesense Docsearch Scraper Setup Issue
Vinicius experienced issues setting up typesense-docsearch-scraper locally. Jason identified a misconfiguration with the Typesense server after checking the .env file, and recommended using ngrok or port forwarding for development purposes. Vinicius successfully resolved the issue with port forwarding.
Troubleshooting Typesense Connection Issue and Data Retrieval
Felix encountered issues connecting to a server-created typesense and retrieving data collections. Kishore Nallan and Jason provided guidance, highlighting errors in the original code and suggesting changes to the URL and curl command.
Server IP Address and Port Issues with Typesense
Alex encountered problems with Typesense server configuration when setting IP and port using --api-address and --api-port, facing additional problems with CORS and version inequities. Kishore Nallan addressed each point, ultimately finding a bug with the command line parser affecting subsequent commands. The advised workaround was to use `--enable-cors=true`.