anuser
07/06/2023, 12:21 PMRequest #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 this
const 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());
<http://app.post|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/typesense-server@0.24.1
brew services start typesense-server@0.24.1
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
07/06/2023, 12:23 PM<http://localhost:8108/health>
in the browser?anuser
07/06/2023, 12:24 PMKishore Nallan
07/06/2023, 12:29 PMconnectionTimeoutSeconds: 2,
and if that does not help, check Typesense logs to see whether any error is loggedanuser
07/06/2023, 1: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
07/06/2023, 1:05 PManuser
07/06/2023, 1:05 PMKishore Nallan
07/06/2023, 1: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 Couble
07/06/2023, 1:18 PMlocalhost
to 127.0.0.1
Kishore Nallan
07/06/2023, 1:19 PManuser
07/06/2023, 1:45 PM