I have been looking around for well over 2 hours now trying to find SOMETHING that would give me any kind of direction with this issue but simply cannot find it.
I am using Node.js and CouchDB with docker-compose. I am also using express and nano. I have stripped my server.js file down to nearly nothing and still keep getting this
Error:
/usr/src/app/node_modules/nano/lib/nano.js:137
reject(new Error('error happened in your connection'))
^
Error: error happened in your connection
at responseHandler (/usr/src/app/node_modules/nano/lib/nano.js:137:16)
at /usr/src/app/node_modules/nano/lib/nano.js:427:13
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Node.js v17.0.1
I have tried about 10 different ways of laying out the url
but just cannot get any kind of indication as to why it just will not work. I have tried using curl -X PUT admin:[email protected]:5984/posts/"001" -d '{"name":"Conner"} '
and it gets inserted without and issue.
server.js
'use strict';
const express = require('express');
var nano = require('nano')('http://admin:[email protected]:5984');
var posts = nano.use('posts');
const app = express();
const bodyParser = require("body-parser");
const cors =require('cors');
app.use(cors());
app.use(bodyParser.urlencoded({
extended: true
}));
const PORT = 8080;
const HOST = '0.0.0.0';
async function asyncCall() {
const response = await posts.insert({_id: "001"}, 'rabbit')
return response
}
asyncCall();
app.use('/', express.static('public'));
console.log('up and running');
app.listen(PORT,HOST);
Dockerfile
FROM node:latest
EXPOSE 8080
WORKDIR /usr/src/app
RUN npm install express --save
RUN npm install nano --save
RUN npm install cors --save
RUN npm install -g loadtest --save
COPY server.js /usr/src/app/server.js
COPY /public /usr/src/app/public
CMD ["node", "server.js"]
docker-compose.yml
version: '3'
services:
node1:
build: ./s1
depends_on:
- couchdb1
container_name: s1a4
ports:
- "81:8080"
couchdb1:
image: couchdb:3.2.0
container_name: cdb1
ports:
- "5984:5984"
environment:
COUCHDB_USER: admin
COUCHDB_PASSWORD: admin
CodePudding user response:
Since CouchDB is running in its own container and not on localhost, your connection string needs to point to the other container instead of 127.0.0.1 (localhost).
Since you called the CouchDB service "couchdb1", the connection string should instead be;
admin:admin@couchdb1:5984