scottksmith95 / beerlocker Goto Github PK
View Code? Open in Web Editor NEWSource code for Beer Locker tutorials
Home Page: http://scottksmith.com/blog/2014/05/02/building-restful-apis-with-node/
Source code for Beer Locker tutorials
Home Page: http://scottksmith.com/blog/2014/05/02/building-restful-apis-with-node/
I noticed in the code that you were using app.use(Body.Parser());
This has been deprecated and I found that it doesn't do the POST data correctly.
I changed it to
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
and it POSTS just fine now.
Thanks so much for the tutorial. It's been a huge help in wrapping my head around Oauth2.
Failed to load c++ bson extension, using pure JS version,how to solve this problem?
⋊> ~/D/OAuth2NodeServer node -v
v6.9.1
⋊> ~/D/OAuth2NodeServer npm -v
3.10.8
macOS Sierra
10.12
Failed to load c++ bson extension, using pure JS version
⋊> ~/D/O/b/beerlocker-6.1 on master ⨯ git clone https://github.com/scottksmitcd
⋊> ~/D/OAuth2NodeServer cd beerlocker/
⋊> ~/D/O/beerlocker on master ⨯ cd beerlocker-6.1/
⋊> ~/D/O/b/beerlocker-6.1 on master ⨯ npm update
⋊> ~/D/O/b/beerlocker-6.1 on master ⨯ node-dev server.js
{ Error: Cannot find module '../build/Release/bson' .......
....
js-bson: Failed to load c++ bson extension, using pure JS version
##############################################################
#
# !!! MONGOOSE WARNING !!!
#
# This is an UNSTABLE release of Mongoose.
# Unstable releases are available for preview/testing only.
# DO NOT run this in production.
#
##############################################################
...
TypeError: Cannot read property 'length' of undefined
Hi,
Am getting this error after adding beer.userId = req.user._id , to the beer controller.
TypeError: Cannot read property '_id' of undefined
Code
beer_controller.js
`var Beer = require('../models/beer');
var User = require('../models/user');
// Create endpoint /api/beers for POST
exports.postBeers = function(req, res) {
// Create a new instance of the Beer model
var beer = new Beer();
// Set the beer properties that came from the POST data
beer.name = req.body.name;
beer.type = req.body.type;
beer.quantity = req.body.quantity;
beer.userId = req.user._id; // where the error is
// Save the beer and check for errors
beer.save(function(err) {
if (err)
return res.send(err);
res.json({ message: 'Beer added to the locker!', data: beer });
});
};
// Create endpoint /api/beers for GET
exports.getBeers = function(req, res) {
// Use the Beer model to find all beer
Beer.find({ userId: req.user._id }, function(err, beers) {
if (err)
return res.send(err);
res.json(beers);
});
};
// Create endpoint /api/beers/:beer_id for GET
exports.getBeer = function(req, res) {
// Use the Beer model to find a specific beer
Beer.find({ userId: req.user._id, _id: req.params.beer_id }, function(err, beer) {
if (err)
return res.send(err);
res.json(beer);
});
};
// Create endpoint /api/beers/:beer_id for PUT
exports.putBeer = function(req, res) {
// Use the Beer model to find a specific beer
Beer.update({ userId: req.user._id, _id: req.params.beer_id }, { quantity: req.body.quantity }, function(err, num, raw) {
if (err)
return res.send(err);
res.json({ message: num + ' updated' });
});
};
// Create endpoint /api/beers/:beer_id for DELETE
exports.deleteBeer = function(req, res) {
// Use the Beer model to find a specific beer and remove it
Beer.remove({ userId: req.user._id, _id: req.params.beer_id }, function(err) {
if (err)
return res.send(err);
res.json({ message: 'Beer removed from the locker!' });
});
};`
Hi, I've following this tutorial to understand the OAuth flow and also to create custom oauth2 server.
Whenever I hit "Allow" button, it shows this error. I saw comments in the blog showing same error faced by the users.
BadRequestError: Missing required parameter: transaction_id
at SessionStore.load (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\oauth2orize\lib\txn\session.js:25:25)
at transactionLoader (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\oauth2orize\lib\middleware\transactionLoader.js:42:24)
at Layer.handle [as handle_request] (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\express\lib\router\route.js:144:13)
at complete (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\passport\lib\middleware\authenticate.js:271:13)
at C:\Users\User\projects\nodejs projects\beerlocker\node_modules\passport\lib\middleware\authenticate.js:278:15
at pass (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\passport\lib\authenticator.js:428:14)
at Authenticator.transformAuthInfo (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\passport\lib\authenticator.js:450:5)
at C:\Users\User\projects\nodejs projects\beerlocker\node_modules\passport\lib\middleware\authenticate.js:275:22
at IncomingMessage.req.login.req.logIn (C:\Users\User\projects\nodejs projects\beerlocker\node_modules\passport\lib\http\request.js:44:13)
Hi,
I wrote same codes as you commit in this repository but when putting a new user via postman, I face this error :
E:\learnJS\SocialNetwork\example-node-server\models\user.js:39
if (!user.isModified('password')) return callback();
^
TypeError: Cannot read property 'isModified' of undefined
my codes: https://github.com/mmdsharifi/skillsharee
and erro : https://github.com/mmdsharifi/skillsharee/blob/28814dce8b47e8dfe7910336360d6586019a03ac/models/user.js#L22
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.