academind / node-restful-api-tutorial Goto Github PK
View Code? Open in Web Editor NEWThis repository accompanies my YouTube series on building a RESTful API with Node.js: https://www.youtube.com/playlist?list=PL55RiY5tL51q4D-B63KBnygU6opNPFk_q
This repository accompanies my YouTube series on building a RESTful API with Node.js: https://www.youtube.com/playlist?list=PL55RiY5tL51q4D-B63KBnygU6opNPFk_q
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" }
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.
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
}
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
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 ?
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?
can you tell me your ide?
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
});
});
});
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.