Code Monkey home page Code Monkey logo

node-restful-api-tutorial's Introduction

node-restful-api-tutorial's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-restful-api-tutorial's Issues

Issues when protecting the Route!!

Screenshot 2020-02-15 at 2 14 25

I tried alot to solve the issue!! I get the token; login and sign up is successful too. But upon using the generated token to protect the Route, I have this above issue!! Why does it have path Error??

Also even though the I get error, I still have have the image uploaded in uploads!!

Error message while posting user signup

Following error showing while using POST for user/signup
error code
{ "error": { "message": "Cannot read property 'email' of undefined" } }

POST code:
{ "email":"test", "password": "password" }
or
{ "email":"[email protected]", "password": "password" }

Add a controller

I am follow your course. This issue is create when i create a controller.

issue

how do i access req.userData in controller

pls I have a challenge after setting up jwt and auth route I am trying to get user details without having to get it from d front end or having to decode the token all d time on all request . am trying to get user details from req.userData in any contoller

Unable to post products

I am following the same procedures as per the source code but still not able to post the data to mlab. Getting the following error in postman:
{ "error": { "message": "ENOENT: no such file or directory, open 'C:\\Users\\Priya\\Desktop\\sample\\node-restful-api-tutorial-13-controllers\\uploads\\2018-06-30T15:31:36.292ZCocker-Spaniel-Puppies-For-Sale-600x600.jpg'" } }

I have tried multiple times the same code but all useless. Kindly help out as soon as possible as it is urgent.

Couldnt delete by ID

i did exactly what you did.. i get response but the item is still there.
response :
{
"n": 0,
"opTime": {
"ts": "6565042526242209793",
"t": 1
},
"electionId": "7fffffff0000000000000001",
"ok": 1
}

UnhandledPromiseRejectionWarning: Can't set headers after they are sent

Hi.
I am getting the following error while using your check-auth middleware in my app:
(node:27860) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.

I believe it has something to do with this:
req.userData = jwt.verify(token, process.env.ACCESS_TOKEN_SECRET);
in check-auth.js

How may I tweak it to work ?

Mongoose Error while Posting Order

Hello Max and all other viewers, love your videos, but in this tutorial I got stuck after implementing the router.post('/', ....), whenever I try to POST the order in postman software it comes out as

{
    "error": {
        "message": "document must have an _id before saving",
        "name": "MongooseError"
    }
}

and nothing gets posted in localhost:3000/orders

I mean why does the mongoose expect the _id to be there first, isn't the productId should suffice for that? I"m sorry if I'm vague , provide any explanation or suggestion that will help me guide

Empty JSON Response on populating orders by Product Model

i got empty json when access get to :http://localhost:3000/orders
{
"count": 0,
"orders": []
}

order.js :

const mongoose = require('mongoose');
const orderSchema = mongoose.Schema({
 _id: mongoose.Schema.Types.ObjectId,
 product: {type:mongoose.Schema.Types.ObjectId, ref:'Product', required: true},
 quantity: {type:Number, default:1}
});

module.exports = mongoose.model('Order',orderSchema)

getroutes :

router.get('/', (req,res,next)=>{
 Order.find()
  .select("product quantity _id")
  .populate('product')
  .exec()
  .then(docs => {
   res.status(200).json({
    count: docs.length,
    orders: docs.map(doc => {
     return {
      _id :doc._id,
      product: doc.product,
      quantity: doc.quantity,
      request: {
       type: 'GET',
       url: `http://localhost:3000/orders/${doc._id}`
      }
     };
    })
   });
  })
 .catch(err => {
  res.status(500).json({
   error: err
  });
 });
});

Commented code

Hey Max, how are you?
Very nice work! Thank you for sharing!

Well, i have a doubt.
It's about the commented code in the "GET" route of the product controller.

node-restful-api-tutorial / api / controllers / products.js (lines: 24 ~ 30)
File in this repo

As my English is somewhat limited, I did not understand everything you explained about while writing this part of the code.
What is the best option? Uncomment or delete commented lines?

Error authenticating user login

I followed your steps for creating a new user. It returned a proper email and id. But now when I try to POST request for /login using postman, it does not work. It shows the following error:

`POST /user/signup 201 819.342 ms - 26
C:\Users\Admin\Desktop\one-way-travel\node_modules\jsonwebtoken\sign.js:97
throw err;
^

Error: secretOrPrivateKey must have a value
at Object.module.exports [as sign] (C:\Users\Admin\Desktop\one-way-travel\node_modules\jsonwebtoken\sign.js:101:20)
at bcrypt.compare (C:\Users\Admin\Desktop\one-way-travel\api\controllers\user.js:63:29)
`

Kindly help to resolve it soon.

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.