error: database "dbName" does not exist Node.js PostgreSQL - node.js

I'm just starting with Node.js and I'm following this tutorial https://dev.to/glaucia86/developing-a-crud-node-js-application-with-postgresql-4c9o
when setting .env file as suggested
DATABASE_URL=postgres://{db_username}:{db_password}#{host}:{port}/{db_name}
so
DATABASE_URL=postgres://vinnytwice:pass#localhost:5432/fixit
I start the server with npm start command when using Postman to send a Post request I get they error in console:
vinnytwice#Vinnys-iMac fixit_server_node % npm start
> fixit_server_node#1.0.0 start
> node server.js
App executing to port 3000
error: database "vinnytwice" does not exist
at Parser.parseErrorMessage (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:369:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
What am I doing wrong ?
Many thanks.

Finally found the problem, the .env file wasn't at the root of the project.

Related

MongoDB error while installing Rocket.chat in CentOS 8 server with Apache

I am following this tutorial to install a Rocket.chat server in CentOS:
https://hostpresto.com/community/tutorials/how-to-install-rocket-chat-server-on-centos-7/
I am new to mongodb and node.js so I am not very familiar with how all this works
At the moment I am looking for something simple that just works
When I reach the step where it says to execute
node main.js
I get the following error:
[username#localhost Rocket.chat]$ node main.js
/opt/Rocket.chat/programs/server/node_modules/fibers/future.js:313
throw(ex);
^
MongoError: not master and slaveOk=false
at Connection.<anonymous> (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/pool.js:450:61)
at Connection.emit (events.js:310:20)
at processMessage (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:384:10)
at Socket.<anonymous> (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:553:15)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12)
at readableAddChunk (_stream_readable.js:268:9)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
ok: 0,
errmsg: 'not master and slaveOk=false',
code: 13435,
codeName: 'NotMasterNoSlaveOk',
[Symbol(mongoErrorContextSymbol)]: {}
}
The tutorial says I should be able to see the Rocket.chat web interface if I go to https://yourdomain.com:3000 but I get an unable to connect page, which I suppose is due to the error above
The tutorial also says node main.js is to check if MongoDB is running or not. I can see that MongoDb service is running by executing
systemctl status mongod
so this error seems to be caused by something else.
How do I find out what is causing this error? Or are there any mistakes in this tutorial? I have found other tutorials regarding installing Rocket.chat in CentOS but most of them use nginx as hte web server while I need to use Apache.

MongoError : command createIndexes requires authentication - mongodb npm

I have a project that I recently put in a production server (not live, but different from my development environment). I configured a mongoDB server with a password authentication.
When I start my Nodejs Application, my usual code retrieve correctly my mongoDB server, returning a client.db object successfully.
But I also have an error popping-in. Something that is not called inside my Nodejs application apparently.
[ERROR] { MongoError: command createIndexes requires authentication
at Connection.<anonymous> (/home/myaccount/myapp/node_modules/mongodb/lib/core/connection/pool.js:460:61)
at Connection.emit (events.js:189:13)
at processMessage (/home/myaccount/myapp/node_modules/mongodb/lib/core/connection/connection.js:368:10)
at Socket.<anonymous> (/home/myaccount/myapp/node_modules/mongodb/lib/core/connection/connection.js:537:15)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
ok: 0,
errmsg: 'command createIndexes requires authentication',
code: 13,
codeName: 'Unauthorized',
name: 'MongoError',
[Symbol(mongoErrorContextSymbol)]: {} }
nothing in the error is pointing toward something I created, it's only about the mongodb npm library. It also giving this error even if a delete every MongoDB connexion related code (but not the mongodb library load).
Do you have any idea how to fix this ?
Okay it's my fault. I had another connexion point that I didn't changed from my express sessions. It's fixed now.
It's just weird the error didn't point toward that module..

UnhandledPromiseRejectionWarning: error: password authentication failed for user " " after npm start

I am using node version 8 and when i do an npm start below errors are seen. I guess after routes are created below errors are seen. Here "techwedge3" is the username of my system. The application works correctly even with the below errors.
Even i am able to connect to my postgres db.
Any idea on how to resolve the issue?
[JobRoute::create] Creating route.
[InterviewRoute::create] Creating route.
[Creating AdminRoute::create] Creating route.
[TenantRoute::create] Creating route.
[CriteriaRoute::create] Creating route.
(node:12212) UnhandledPromiseRejectionWarning: error: password authentication failed for user "techwedge3"
at Connection.parseE (C:\Development\vilearnnew\vilearn_node\node_modules\pg-promise\node_modules\pg\lib\connection.js:546:11)
at Connection.parseMessage (C:\Development\vilearnnew\vilearn_node\node_modules\pg-promise\node_modules\pg\lib\connection.js:371:19)
at Socket.<anonymous> (C:\Development\vilearnnew\vilearn_node\node_modules\pg-promise\node_modules\pg\lib\connection.js:114:22)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)

unable to run node js continuously on dedicated windows server

I have a Dedicated windows server, I am running my node express code on the server, but when an exception occurred like
error: remaining connection slots are reserved for non-replication superuser connections
at Connection.parseE (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:554:11)
at Connection.parseMessage (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:381:17)
at TLSSocket.<anonymous> (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:117:22)
at TLSSocket.emit (events.js:180:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onread (net.js:578:20)
Emitted 'error' event at:
at Connection.<anonymous> (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\client.js:183:19)
at Connection.emit (events.js:180:13)
at TLSSocket.<anonymous> (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:121:12)
at TLSSocket.emit (events.js:180:13)
[... lines matching original stack trace ...]
at TLSWrap.onread (net.js:578:20)
and another error like "too many connections to the user on database" error also occurs and stops the execution of the code. this makes a huge loss of the data for me.
I want to run the Node Js Code continuously and to start the execution again if it stopped unexpectedly.
I am running the code using command "npm start" in windows server...
I want this node code to run only on the windows dedicated server.

Heroku fails to load page. MongoError: Authentication failed

I been trying to upload my app to Heroku But I keep getting this MongoError: authentication fail error. I have both username and password correctly. Can someone help me out. I tried installing different version But no use.
running mongod --version
db version v3.4.4
git version: 888390515874a9debd1b6c5d36559ca86b44babd
In my package.json I have
"dependencies": {
"mongoose": "^4.4.12",
"mongoose-unique-validator": "^1.0.2"
},
app.js
var mongoose = require('mongoose');
mongoose.connect('<username>:<password>#ds129023.mlab.com:29023/ng2');
heroku logs:-
throw er; // Unhandled 'error' event
MongoError: Authentication failed.
at Function.MongoError.create (/app/node_modules/mongodb-
core/lib/error.js:31:11)
at /app/node_modules/mongodb-core/lib/connection/pool.js:497:72
^
at authenticateStragglers (/app/node_modules/mongodb-
core/lib/connection/pool.js:443:16)
at Connection.messageHandler (/app/node_modules/mongodb-
core/lib/connection/pool.js:477:5)
at Socket.<anonymous> (/app/node_modules/mongodb-
core/lib/connection/connection.js:321:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
Thanks
You are not providing protocol name here
var mongoose = require('mongoose');
mongoose.connect('mongodb://<username>:<password>#ds129023.mlab.com:29023/ng2');
I added mongodb before username. Try with this, it should work.
I had the same problem.
Make sure that you've created a user for your database
For case with "admin" user, it could be:
mongoose.connect('mongodb:admin:#ds129023.mlab.com:29023/ng2');
I have faced the same problem in my case I have not added config vars in Heroku app.
Go to Heroku website > Your App > Settings > Reveal Config Vars and add your environment variables there.
As You Can see in the following image.

Resources