简体   繁体   English

Mongo身份验证在Node.js应用程序中失败

[英]Mongo Authentication Failed in Nodejs Application

I am beginner in nodejs . 我是nodejs的初学者。 I am developing a simple chat application and I am trying to run the app.js file in development mode then it is fine. 我正在开发一个简单的聊天应用程序,并且尝试在开发模式下运行app.js文件,所以很好。 But when I am tring it into the production mode it does not work and give a authentication error. 但是,当我将其转换为生产模式时,它将无法正常工作并给出身份验证错误。 (as shown in the picture below) CODE :- (如下图所示)代码:-

 var express = require('express'), app = express(), path = require('path') cookieParser = require('cookie-parser') session = require('express-session') config = require('./config/config.js'), ConnectMongo = require('connect-mongo')(session); app.set('views', path.join(__dirname , 'views')); app.engine('html', require('hogan-express')); app.set('view engine', 'html'); app.use(express.static(path.join(__dirname,'public'))); app.use(cookieParser()); var env = process.env.NODE_ENV || 'development'; if(env === 'development'){ // dev specific settings app.use(session({secret:config.sessionSecret, saveUninitialized : true, resave : true})); } else { //Production specific settings app.use(session({ secret : config.sessionSecret, saveUninitialized : true, resave : true, store : new ConnectMongo({ url : config.dbURL, stringify : true }) })); } require('./routes/routes.js')(express,app); app.listen (3000 , function(){ console.log("ChatUp working on the Port 3000"); console.log('Mode:'+ env); }); 

Picture of Window CMD :- Error Picture 窗口CMD的图片:-错误图片

Help Me to get rid of this error 帮我摆脱这个错误

The issue was because I was using my mongolab.com username and password, instead of the database username and password. 问题是因为我使用的是mongolab.com用户名和密码,而不是数据库的用户名和密码。

It is working now. 现在正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM