Nest server not connecting to MongoDB cloud UnhandledPromiseRejectionWarning: MongoParseError: URI malformed - node.js

My NestJS backend needs to connect to the mongodb cloud, I followed the docs from here
The following error threw up in the terminal:
(node:6920) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed
at new ConnectionString (D:\growth\quizbackend\quizbackend\node_modules\mongodb-connection-string-url\src\index.ts:113:13)
at Object.parseOptions (D:\growth\quizbackend\quizbackend\node_modules\mongodb\src\connection_string.ts:249:15)
at new MongoClient (D:\growth\quizbackend\quizbackend\node_modules\mongodb\src\mongo_client.ts:332:22)
at D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\connection.js:785:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\connection.js:782:19)
at Mongoose.createConnection (D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\index.js:275:10)
at Function.<anonymous> (D:\growth\quizbackend\quizbackend\node_modules\#nestjs\mongoose\dist\mongoose-core.module.js:60:63)
at Generator.next (<anonymous>)
at D:\growth\quizbackend\quizbackend\node_modules\#nestjs\mongoose\dist\mongoose-core.module.js:20:71
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6920) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:6920) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,
promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
My app module code:
import { Module } from '#nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './users/users.module';
import {MongooseModule} from '#nestjs/mongoose'
#Module({
imports: [UsersModule,MongooseModule.forRoot('mongodb+srv://icfoajscijwq90j#cluster0.8rxa2.mongodb.net/nest-js-db?retryWrites=true&w=majority')],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
I doubled check my username and password but they are correct, is there any need for encoding them or why the error is throwing up any explanation would be appreciated.

Ensure that your username and password in the URI Connection string doesn't have any illegal characters.
If the username or password includes the following characters:
: / ? # [ ] #
those characters must be converted using percent encoding.
Based on their documentation: https://docs.mongodb.com/manual/reference/connection-string/

Related

Why telegram bot don't work if participants left group or new one add to group?

When I run my app and someone in group left or new participant add to group, my bot stop working.
Below you can see code of my app:
const TelegramBot = require('node-telegram-bot-api');
const token = '1928095766:AAGf5aU7E1_FAM_fWzQs3SSGy-1AJS0DjcY';
const bot = new TelegramBot(token, { polling: true });
bot.on('message', async msg => {
const reg = /\d\d\-\d\d$/;
if (msg.text.match(reg)) {
bot.sendMessage(msg.chat.id, 'Gh')
}
})
And what I received in terminal if someone left group or new one add into, when my app is running:
(node:21155) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
at TelegramBot.<anonymous> (/Users/romansavka/Telegram-Bot-Node/telegram-bot/reminder.js:11:30)
at TelegramBot.emit (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/eventemitter3/index.js:182:35)
at TelegramBot.processUpdate (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:634:12)
at /Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:110:22
at Array.forEach (<anonymous>)
at /Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/node-telegram-bot-api/src/telegramPolling.js:106:17
at tryCatcher (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues (/Users/romansavka/Telegram-Bot-Node/telegram-bot/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:462:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21155) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:21155) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
It's because the message received has no attribute text, so the error raised UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined

Error: A circular dependency has been detected (property key: "firstName") thrown by tx-mixer

I'm using this wonderful lib: https://www.npmjs.com/package/ts-mixer
The whole traceback looks as follows:
(node:22654) UnhandledPromiseRejectionWarning: Error: A circular dependency has been detected (property key: "firstName"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
at SchemaObjectFactory.createNotBuiltInTypeReference (/Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:212:19)
at SchemaObjectFactory.mergePropertyWithMetadata (/Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:143:25)
at /Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:79:35
at Array.map (<anonymous>)
at SchemaObjectFactory.extractPropertiesFromType (/Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:78:52)
at SchemaObjectFactory.exploreModelSchema (/Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:92:41)
at /Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:33:36
at Array.map (<anonymous>)
at SchemaObjectFactory.createFromModel (/Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:20:45)
at exploreApiParametersMetadata (/Users/albert/Documents/projects/albert/rlx/node_modules/#nestjs/swagger/dist/explorers/api-parameters.explorer.js:33:55)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22654) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22654) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
register-common-user.dto.ts
export class RegisterCommonUserDto {
#decorate(ApiProperty())
#decorate(IsNotEmpty())
#decorate(IsString())
firstName: string;
// #decorate(ApiProperty())
#decorate(IsNotEmpty())
#decorate(IsString())
lastName: string;
// #decorate(ApiProperty({enum: EUserRoleName}))
#decorate(IsNotEmpty())
#decorate(IsEnum(EUserRoleName))
roleName: EUserRoleName;
// #decorate(ApiProperty())
#decorate(IsNotEmpty())
#decorate(IsPhoneNumber())
phoneNumber: string;
// #decorate(ApiProperty())
#decorate(IsNotEmpty())
#decorate(IsEmail())
email: string;
}
register-user.dto.ts
export class RegisterUserDto extends Mixin(
RegisterFighterDto,
RegisterCommonUserDto,
RegisterLocationProviderDto,
) {}
The method:
#Post('register')
public async registerUser(#Body() registerUserDto: RegisterUserDto): Promise<any> {
// code
}
What might be causing the problem? It has surely something to do with the #ApiProperty decorator being wrapped in decorate, cos when I comment out that line, the error disappears. But in that case decorators don't get inherited and that's the whole point of using the ts-mixer lib.
EDIT:
Any ideas?
EDIT:
Are these libs incompatible or what?
Recently, I learning Nest also have the same problem when attempt to use Swagger. This is my whole traceback looks as follows:
Error: A circular dependency has been detected (property key: "user"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
at SchemaObjectFactory.createNotBuiltInTypeReference (/Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:170:19)
at SchemaObjectFactory.createSchemaMetadata (/Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:277:25)
at SchemaObjectFactory.mergePropertyWithMetadata (/Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:122:21)
at /Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:79:35
at Array.map (<anonymous>)
at SchemaObjectFactory.extractPropertiesFromType (/Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:78:52)
at SchemaObjectFactory.exploreModelSchema (/Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:92:41)
at /Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/swagger-explorer.js:217:64
at Array.forEach (<anonymous>)
at SwaggerExplorer.registerExtraModels (/Users/wujie/Code/realworld/nestjs-realworld-example-app/node_modules/#nestjs/swagger/dist/swagger-explorer.js:217:21)
Analyze the error code information,I found the problem is the decorator ApiExtraModels(), and the code I wrote is:
import { applyDecorators, Type } from '#nestjs/common';
import { ApiOkResponse, ApiExtraModels, getSchemaPath } from '#nestjs/swagger';
import { ApiUserResDto, PaginatedDto } from './dto/api-res.dto';
/** 用户信息返回限定装饰器 */
export const ApiUserResponse = <TModel extends Type<any>>(model: TModel) => {
return applyDecorators(
ApiOkResponse({
schema: {
title: `UserResponseOf${model.name}`,
allOf: [
{ $ref: getSchemaPath(ApiUserResDto) },
{
properties: {
user: {
type: 'object',
$ref: getSchemaPath(model)
}
}
}
]
}
}),
ApiExtraModels(ApiUserResDto),
ApiExtraModels(model)
);
};`
and the apiUserResDto class is:
export class ApiUserResDto<Dto> {
user: Dto;
}
according to the cli tips, just change ApiExtraModels(ApiUserResDto) to ApiExtraModels(() => ApiUserResDto), should solve this problem.

Parse Sever with custom Express app Master Key Permission Denied

We have a custom express app that loads in the node.js parse server sdk. When we try to use a function call that requires the master key we keep getting errors for permission denied.
at /Users/gateway/Documents/lm/Website/lm-node/node_modules/parse/lib/node/RESTController.js:324:19
at processTicksAndRejections (internal/process/task_queues.js:86:5)
(node:61092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:61092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
we initiate our parse server like this..
Parse.initialize(process.env.PARSE_STAGING_APP_ID, null, process.env.PARSE_STAGING_MASTER_KEY);
//Parse.Cloud.useMasterKey();
Parse.serverURL = process.env.PARSE_STAGING_SERVER_URL;
Parse.User.enableUnsafeCurrentUser();
module.exports = Parse
async function channelStatus(orgId) {
const Status = Parse.Object.extend("Status");
const query = new Parse.Query(Status);
query.equalTo("orgID", orgId);
try {
const results = await query.first({useMasterKey: true});
if(results) {
// do some stuff
results.save();
} else {
const StatusNew = Parse.Object.extend("Status");
const statusNew = new StatusNew();
// do some stuff
statusNew.save()
}
} catch (error) {
throw error;
}
}
if we enable Parse.Cloud.useMasterKey(); it works but this can be bad because it works for every function.. we want to make sure we are using masterKey on certain functions..
thoughts?
full error in visual studio.
(node:35145) UnhandledPromiseRejectionWarning: Error: Permission denied for action get on class Status.
at /Users/gateway/Documents/lmx/WebSite/lmx/node_modules/parse/lib/node/RESTController.js:324:19
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:35145) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:35145) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
GET /test - - ms - -
Logs
Jul 29 13:08:29 lmx-stage app/web.1: error: Error generating response. ParseError {
Jul 29 13:08:29 lmx-stage app/web.1: code: 119,
Jul 29 13:08:29 lmx-stage app/web.1: message: 'Permission denied for action get on class Status.' } code=119, message=Permission denied for action get on class Status.
Jul 29 13:08:29 lmx-stage app/web.1: error: Permission denied for action get on class Status. code=119, message=Permission denied for action get on class Status.

how to fix: 'MongoError: authentication fail' #MongoDB Atlas

I am connecting to MongoDB Atlas and getting authentication fail error.
that is my connection string:
mongodb://user:<password>#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
That is what I get:
------------------------------------------------
Mongoose connection "error" event fired with:
{ MongoError: authentication fail
at Function.MongoError.create (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:31:11)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/replset.js:1245:38
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:760:7
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:736:20
at finish (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:168:16)
at handleEnd (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:178:7)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:269:11
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:469:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017',
err: [Error] },
{ name: 'mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017',
err: [Error] } ] }
Error: KeystoneJS (Keystone Demo) failed to start - Check that you are running `mongod` in a separate process.
at NativeConnection.<anonymous> (/mnt/c/WEB/keystone-md2/node_modules/keystone/lib/core/openDatabaseConnection.js:62:10)
at NativeConnection.emit (events.js:189:13)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/lib/connection.js:824:17
at connectCallback (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:527:5)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:459:13
at process._tickCallback (internal/process/next_tick.js:61:11)
You have to put your user and password in your connection uri string
mongodb://***'your user':' here comes password '***#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
e.g
mongodb://dbuser:dbpassword#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
The problem is I was leaving <> in connection string. You have to remove those for authentication to work.
I was facing this issue too. But after an hour I came to know that I used the process.env variables for username and password. And also declared them in the .env file. But I forgot to configure dotenv package in my code.
So make sure you didn't make this kind of silly mistake.
For more info go through this documentation of node repositories.
https://www.npmjs.com/package/dotenv
I have a similar error but with connecting to the new Atlas database. Even though I have definitely setup the username and password correctly as stated here and in the documentation (obviously i replaced PASSWORD with my correct MLAB password:
var mongoURI = 'mongodb+srv://heroku_3kcdl3j9:PASSWORD#cluster-3kcdl3j9.auof1.mongodb.net/heroku_3kcdl3j9?retryWrites=true&w=majority';
I have migrated my database from MLAB to Atlas successfully set the correct Network access settings to 0.0.0.0 IP addresss. Setup the environment variable in Heroku. But still get this error:
{ MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'cluster-3kcdl3j9-shard-00-01.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-00.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-02.auof1.mongodb.net:27017',
err: [MongoError] } ],
[Symbol(mongoErrorContextSymbol)]: {} }
(node:47015) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 's' of undefined
at Admin.buildInfo (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb/lib/admin.js:100:37)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/index.js:95:13
at $initialConnection.then.err (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongoose/lib/connection.js:556:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:47015) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:47015) UnhandledPromiseRejectionWarning: MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I had a similar error and in my case, the problem was I have added (whitelisted) a wrong IP address in "IP Access List" on "Security -> Network Access" page.

Module.exports not finding function

So I am creating a basic user login system (this is one of my first nodejs projects) and I am wanting to redirect the user to the 'dashboard' page with a successful login.
First of all I am not sure this is the best way to do the redirecting so I am open to suggestions.
The problem I am having is after calling the function and the user logs in I want to call this function:
var loginResponse = () =>{
io.emit('loginResponse');
}
This is in the server.js file (the main server file) and I am exporting it like so
module.exports = {
loginResponse : loginResponse
};
I am then after all the validation, calling db etc. is done wanting to call it in the login.js file as shown:
var createUserSession = (userSessionObj) =>{
session.user = userSessionObj;
serverMain.loginResponse();
};
I am requiring the file server file like so:
const serverMain = require('../server');
However, I am getting the following error on execute:
(node:35012) UnhandledPromiseRejectionWarning: TypeError: serverMain.loginResponse is not a function
at createUserSession (/Users/chrisholder/Documents/Programming/RandomPrograms/registerlogin/server/registrationlogin/login.js:83:14)
at hashing.comparePassword.then (/Users/chrisholder/Documents/Programming/RandomPrograms/registerlogin/server/registrationlogin/login.js:73:7)
at <anonymous>
(node:35012) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:35012) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I have tried using the 'path' module as another way to requiring the server.js file however, it has not worked.
Thanks for your help!

Resources