Code Monkey home page Code Monkey logo

rest-api-nodejs-mongodb's Issues

[Suggestion]

I guess adding the tests also a plus point in the provided structure?

Form Data

I am sending form data but it didn't get it from server side,

Cannot post array

This is my post request with body as application/json format from postman

`{"title": "test",
        "date": "March 12 12 pm",
       
        
        "status": "Ongoing",
       
		"users": ["1","2"]
}`

But in nodejs when i try to retrieve req.body users am getting only 1 as output but not whole array.

endpoints?

i have successfully installed and started the server, and maybe i missed something somewhere, but how do i actually access the api? i load localhost:3000 and it shows the title and byline that should come up, but what do i add to the url to actually get json back?

Starting out for beginners

Hello!

I'm new to mongo, and I really appreciate the help getting my API started.
I did an npm i, then set my mongo url, and started my mongo service, then ran npm test, but I'm having some "connection refused" errors. Do I have to manually create the databases in mongo?

Thanks

Getting error Error: Cannot find module 'bcrypt'

2021-07-19T09_57_53_633Z-debug.log

I have checked package json file but bcrypt package already available

Error: Cannot find module 'bcrypt'
Require stack:

  • E:\angular\kanhashoft\Node-With-Mongo\test\myproject\controllers\AuthController.js
  • E:\angular\kanhashoft\Node-With-Mongo\test\myproject\routes\auth.js
  • E:\angular\kanhashoft\Node-With-Mongo\test\myproject\routes\api.js
  • E:\angular\kanhashoft\Node-With-Mongo\test\myproject\app.js
  • E:\angular\kanhashoft\Node-With-Mongo\test\myproject\bin\www
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object. (E:\angular\kanhashoft\Node-With-Mongo\test\myproject\controllers\AuthController.js:7:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object. (E:\angular\kanhashoft\Node-With-Mongo\test\myproject\routes\auth.js:2:24)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'E:\angular\kanhashoft\Node-With-Mongo\test\myproject\controllers\AuthController.js',
    'E:\angular\kanhashoft\Node-With-Mongo\test\myproject\routes\auth.js',
    'E:\angular\kanhashoft\Node-With-Mongo\test\myproject\routes\api.js',
    'E:\angular\kanhashoft\Node-With-Mongo\test\myproject\app.js',
    'E:\angular\kanhashoft\Node-With-Mongo\test\myproject\bin\www'
    ]
    }

Refactor If Statements.

We can refactor these if statements with Guard Clauses

if (!errors.isEmpty()) {
return apiResponse.validationErrorWithData(res, "Validation Error.", errors.array());
}else {
UserModel.findOne({email : req.body.email}).then(user => {
if (user) {
//Compare given password with db's hash.
bcrypt.compare(req.body.password,user.password,function (err,same) {
if(same){
//Check account confirmation.
if(user.isConfirmed){
// Check User's account active or not.
if(user.status) {
let userData = {
_id: user._id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
};
//Prepare JWT token for authentication
const jwtPayload = userData;
const jwtData = {
expiresIn: process.env.JWT_TIMEOUT_DURATION,
};
const secret = process.env.JWT_SECRET;
//Generated JWT token with Payload and secret.
userData.token = jwt.sign(jwtPayload, secret, jwtData);
return apiResponse.successResponseWithData(res,"Login Success.", userData);
}else {
return apiResponse.unauthorizedResponse(res, "Account is not active. Please contact admin.");
}
}else{
return apiResponse.unauthorizedResponse(res, "Account is not confirmed. Please confirm your account.");
}
}else{
return apiResponse.unauthorizedResponse(res, "Email or Password wrong.");
}
});
}else{
return apiResponse.unauthorizedResponse(res, "Email or Password wrong.");
}
});
}
} catch (err) {
return apiResponse.ErrorResponse(res, err);
}
}];

Does not work with Google SMTP

Hi,

I have enabled SMTP on GMAIL and trying to use this code but getting this error while using the following API
http://localhost:3000/api/auth/register

Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials c4-c35345.73 - gsmtp 
{
    "status": 0,
    "message": {
        "code": "EAUTH",
        "response": "535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8  https://support.google.com/mail/?p=BadCredentials b29-c34543- gsmtp",
        "responseCode": 535,
        "command": "AUTH PLAIN"
    }
}
EMAIL_SMTP_HOST=smtp.gmail.com
EMAIL_SMTP_PORT=465
EMAIL_SMTP_USERNAME=tried both email id and only account name
EMAIL_SMTP_PASSWORD=password goes here
# true for 465, false for other ports
EMAIL_SMTP_SECURE=true

Any idea on how to fix this.

RPC instead of REST

How about using RPC?

For example, I developed an RPC implementation for Node.js Wildcard API.

I'd be curious to know what you think about using RPC instead of REST.

Internal APIs not working

Hi the APIs are not functional.

I setup the .env with mongoDB details and skipped SMTP. But anyhow the functionalities not dependent on SMTP were also breaking when I ran npm test

Please suggest.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.