madhums / node-express-mongoose-demo Goto Github PK
View Code? Open in Web Editor NEWA simple demo app using node and mongodb for beginners (with docker)
Home Page: https://nodejs-express-demo.fly.dev
License: MIT License
A simple demo app using node and mongodb for beginners (with docker)
Home Page: https://nodejs-express-demo.fly.dev
License: MIT License
App allows duplicate email id registration and inserts duplicate user records to the database..
Using Ubuntu 12.04, I'm seeing a loop that is creating thousands of duplicate images and fillng up the /tmp directory. Imager successfully creates and uploads mini_ and detail_ files, but then goes nuts on the thumbnail (thumb_*), and all of those end up in the /tmp dir.
I think the problem is in the config/imager.js file. I will create a pull request if I get it sorted out.
TomV
Hey, nice job on this. Very useful. Just noticed a small issue. If you select "9" or "10" on the pagination you get a 500 error. I've logged in a couple of times and played around a little. Seems to only happen on 9 or 10, 11 is fine.
Hi;
After saving a document, I want to redirect to the page with paging. How can I do that?
Hey,
I cloned this projekt and followed the instructions.
I set up my googleId, googleSecret and my mongoUrl.
When i execute this code i cannot login via Google-Login.
I get the following error:
[Error: key $t must not start with '$']
Error: key $t must not start with '$'
at Error (unknown source)
at Function.checkKey (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1419:11)
at serializeObject (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:355:14)
at packElement (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
at serializeObject (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:359:15)
at packElement (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
at serializeObject (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:343:15)
at packElement (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
at serializeObject (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:359:15)
at packElement (/var/lib/stickshift/5136d6df5973ca3eab0003b4/app-root/data/426887/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
I cannot push the google response to mongodb.
When i comment profile._json assigned to google
// , google: profile._json
everything is working fine.
Maybe it is more an mongoose error?
How to handle this error?
Hi madhums,
I run app.js show error follow
module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module 'yaml-config'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object. (C:\E-Learning\1_development\1_code\Elearning_V1\app.js:16:19)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
I not yaml-config file,woudl you give me it
Thanks
On regular user signup, the registration is done and user gets logged just fine. But after user logsout and tries to login again with the same email/password, login fails with err: "Invalid email or password."
Thanks
Amir
Hi thanks for building this app, its been really helpful.
So I was trying to upload images with the node-imager linked to my S3 bucket.
I get an error saying "Have you installed graphicsmagick", when i try to upload an image.
I did the following:
Anyone have any idea whats causing it, or how to fix this?
Thanks its probably something simple.
Command line stack:
Express app started on port 3000
GET / 304 519ms
GET /articles/new 304 101ms
{ [Error: Command failed: CreateProcessW: The system cannot find the file specified.
** Have you installed graphicsmagick? **
] code: 127, signal: null }
[ '' ]
The demo app is a very good starting point app..Is there anyway you can add the attachment upload and the tinymce editor to the blog app..
today i made a clone of your project and i found out some bugs/crashes:
thank you a lot
I ran projects in local with mongolab db.
This project request took 900-1500ms, it is obviously slow than other project with same mongolab db , those projects' request only took only 100-200ms, including compoundjs project.
And I found every request called article function two times, for example, I put console.log in getTag and always seeing tags for 2 times by each request.
Why it is slow?
BTW, how does console show req.method and req routes info each request, I didn't find the middleware doing that.
logs:
{ [Error: getaddrinfo ENOENT] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
[ '' ]
stream.js:81
throw er; // Unhandled stream error in pipe.
^
Error: getaddrinfo ENOENT
at errnoException (dns.js:31:11)
at Object.onanswer as oncomplete
I am sure the S3 [key / secret / bucket / region] are correct in imager.js.
thanks.
/edgar
I love this demo! Thank you so much. It's very helpful.
There's a small problem with the pagination system: the first page number called 0, but the pagination control starts numbering at 1. Usually pagination systems have links like the following. Assuming we are on page three of a five-page list:
First: goes to first page
Prev: goes to previous (second) page
1: goes to first page
2: goes to second page
3: is not a link
4: goes to fourth page
5: goes to fifth page
Next: goes to next (fourth) page
Last: goes to last (fifth) page
I'm thinking if you were to have this customized for a mobile alternative, would you simply create a views-mobile, or would it be more involved than that?
Features i would like to see implemented are ability to tag and assign categories to posts. I would also like to see "fancy" urls like domain/year/month/day/slug.
Thanks!
I'd love to see EveryAuth or some sort of Authentication implemented (preferably using password or openID).
Thanks for an awesome demo!
hello, i'm try login with Google authentication but error
Oops something went wrong
500
Error: key $t must not start with '$'
at Error ()
at Function.checkKey (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1419:11)
at serializeObject (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:355:14)
at packElement (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
at serializeObject (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:343:15)
at packElement (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
at serializeObject (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:359:15)
at packElement (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
at serializeObject (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:343:15)
at packElement (/app/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:854:23)
This is one reason I've looked at Singly.com, which I think helps tie all of the user's different accounts together, although I haven't gotten that deep into the passport/node GitHub example, which doesn't use a DB but is only for authentication.
Would doing that with this app be possible? It's easy for users to forget which account they signed in with last time, and then they create a whole new account, and get frustrated at the fact that all the information they saved is gone(I'm developing an elearning app so they are saving all their data to the db).
I'll take another look at the singly example, and see if I could integrate it in this app - but this is way beyond my current js coding abilities!
if I changed to 0.28, it works.
beignners -> beginners
Sorry for the nitpick. This app has a great structure.
Hi,
Would it be possible to add the ajax search functionality to the articles?
I have one unauthorized and one authorized, how can i have only one, normally it should be only one session per browser
Maybe I'm being really stupid here but I can't seem to figure out what is needed to grab and display a logged in users avatar. What additional code or information do I need?
I've been playing around with this demo and it is very good. I have an issue with trying to display the error messages from the passport local strategy e.g. Unknown user, Invalid password
In passport.js the messages are being set correctly.
In reading up about Passport the messaging seem to use the deprecated flash messaging. These are triggered by setting the failureFlash variable in the routes file.
//current format
app.post('/users/session', passport.authenticate('local', {failureRedirect: '/login'}), users.session)
//failureFlash set to true
app.post('/users/session', passport.authenticate('local', {failureRedirect: '/login', failureFlash: true}), users.session)
As Express 3.x doesn't support flash messages the connect-flash module would be required. I have been playing around with this set-up but haven't been able to get the messages to display. Have you found a way to display the message using this approach or another approach?
Hello!
I'm try run app on cloudfoundry.com but it had problem with error
module.js:340
throw err;
^
Error: Cannot find module '/var/vcap/data/dea/apps/blogtest2-0-b62bf0c2012c6adcc1c866144d55e2be/app/NODE_ENV=development'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Can you tell me why?
Thank you!
It may seem pretty weird/trivial, but I'm able to upload any images locally, then the server hangs and there is no write to the database. On Appfrog, the images are uploaded to the S3 bucket but then it times out to a 502 Bad Gateway.
However, on Heroku I'm able to upload images and publish articles. Is there some configuration setting that I'm missing?
(Using a MongoHQ to host the database.)
at exports.create (d:\dev\node_apps\biosync\app\controllers\comments.js:18:11)
I don't know what I did, but I can't add comments anymore.
req.articles is always undefined.
exports.create = function (req, res) {
var article = req.article;
var user = req.user;
console.log(req);
if (!req.body.body) return res.redirect('/articles/'+ article.id);
article.addComment(user, req.body, function (err) {
if (err) return res.render('500');
res.redirect('/articles/'+ article.id);
});
};
Any ideas ? Thanks
Hi;
My activity schema is:
var ActivitySchema = new Schema({
venue: {type : Schema.ObjectId, ref : 'Venue'}
, user: {type : Schema.ObjectId, ref : 'User'}
, createdAt: {type : Date, default : Date.now}
})
mongoose.model('Activity', ActivitySchema)
It is working in local. But when I deploy it to Heroku, I am getting:
2012-12-27T23:12:02+00:00 app[web.1]: MissingSchemaError: Schema hasn't been registered for model "Activity".
2012-12-27T23:12:02+00:00 app[web.1]: Use mongoose.model(name, schema)
2012-12-27T23:12:02+00:00 app[web.1]: at Mongoose.model (/app/node_modules/mongoose/lib/index.js:261:13)
2012-12-27T23:12:02+00:00 app[web.1]: at Object.<anonymous> (/app/app/models/user.js:8:25)
2012-12-27T23:12:02+00:00 app[web.1]: at Module._compile (module.js:449:26)
2012-12-27T23:12:02+00:00 app[web.1]: at Object.Module._extensions..js (module.js:467:10)
2012-12-27T23:12:02+00:00 app[web.1]: at Module.load (module.js:356:32)
2012-12-27T23:12:02+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2012-12-27T23:12:02+00:00 app[web.1]: at Module.require (module.js:362:17)
2012-12-27T23:12:02+00:00 app[web.1]: at require (module.js:378:17)
2012-12-27T23:12:02+00:00 app[web.1]: at /app/server.js:24:3
2012-12-27T23:12:02+00:00 app[web.1]: at Array.forEach (native)
2012-12-27T23:12:04+00:00 heroku[web.1]: Process exited with status 1
2012-12-27T23:12:04+00:00 heroku[web.1]: State changed from starting to crashed
Any idea why I am getting this error?
Hi, since some weeks I am experimenting with node and came across your very nice example. I am trying to extend this to work with socket.io, cluster, i18n and so on. First thing I tried was to create a new model of a “blog”.
Now here comes the catch: I created the model, controller, routes and extended the authorization following your best practices pattern. All works fine but when I save a new article the controller sometimes has the article ID or the blog ID in memory. It cannot differentiate between both models and constantly mixes them up randomly.
Would like to send the example to you but email bounces back.
I'm not too deep in the specifics, but wherever I go Chai seems to be the recommended library for Mocha tests. Maybe you could consider replacing Should with Chai.
It could be very cool if you add production steps like minimisation assets, several config for dev and prod and anything else
npm install not ok
npm ERR! git clone ssh://git://github.com/madhums/node-compress.git cloning into /tmp/npm-1338396012955/1338396012955-0.1640495721548796....
npm ERR! git clone ssh://git://github.com/madhums/node-compress.git ssh: could not resolve hostname git:: Name or service not know
npm ERR! git clone ssh://git://github.com/madhums/node-compress.git fatal: the remote end hung up unexpectedly
npm ERR! ErrorL 'git' "clone" ssh://git://github.com/madhums/node-compress.git /tmp/npm-1338396012955/1338396012955-0.1640495721548796 failed with 128
npm ERR! at ChildProcess. (/usr/lib/node_modules/npm/lib/utils/exec.js:58:20)
npm ERR! at ChildProcess.emit (event.js:70:17)
npm ERR! at maybeExit (child_process.js:362:16)
.....
npm ERR! system Linux 3.0.0-12-generic
npm ERR! command 'node' '/usr/bin/npm' 'install'
npm ERR! node -v 0.6.18
npm ERR! npm -v 1.1.23
...
npm not ok
Hey there. Thank you so much for this example. I'm a noob at node and express so seeing this is awesome for 'best practices'. Thanks for posting!
I am attempting to add Socket.io into this project for some realtime updating, but, it looks like the routing is kicking back a 404 on the client-side line: <script src="/socket.io/socket.io.js"></script>
I'm not even sure that I'm on the right path to figuring this out, but my question is, how would you ignore that route (my guess is it's looking in /public/ ... which doesn't exist), and let it go through to wherever that file is (i'm not event sure where that is...)
in 404.jade and 500.jade
v0.10.10
GET /articles/51da5bae0fd27eb10d000003/edit 200 63ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
/home/emkei/projects/mg/node_modules/mongoose/lib/index.js:272
throw new mongoose.Error.OverwriteModelError(name);
^
OverwriteModelError: Cannot overwrite Resorts
model once compiled.
at Mongoose.model (/home/emkei/projects/mg/node_modules/mongoose/lib/index.js:272:13)
at Object. (/home/emkei/projects/mg/app/models/resort.js:16:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at /home/emkei/projects/mg/server.js:16:3
at Array.forEach (native)
$npm install -> npm not ok
npm http 304 https://registry.npmjs.org/mongoose/2.4.9
npm http 304 https://registry.npmjs.org/gzippo/0.1.2
npm WARN deprecated [email protected]: critical bug fixed in v0.1.4
npm http 304 https://registry.npmjs.org/yaml-config/0.1.0
npm ERR! git clone [email protected]:madhums/node-compress.git Cloning into /tmp/npm-1332758574868/1332758574868-0.8424466820433736...
npm ERR! git clone [email protected]:madhums/node-compress.git
npm ERR! git clone [email protected]:madhums/node-compress.git Permission denied (publickey).
npm ERR! git clone [email protected]:madhums/node-compress.git fatal: The remote end hung up unexpectedly
npm ERR! Error: git "clone" "[email protected]:madhums/node-compress.git" "/tmp/npm-1332758574868/1332758574868-0.8424466820433736"
failed with 128
npm ERR! at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! at ChildProcess.emit (events.js:70:17)
npm ERR! at maybeExit (child_process.js:361:16)
npm ERR! at Socket. (child_process.js:466:7)
npm ERR! at Socket.emit (events.js:67:17)
npm ERR! at Array.0 (net.js:320:10)
npm ERR! at EventEmitter._tickCallback (node.js:192:40)
npm ERR! You may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]
npm ERR!
npm ERR! System Linux 3.0.0-16-generic-pae
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /home/abhishek/nodebase/demo
npm ERR! node -v v0.6.8
npm ERR! npm -v 1.1.0-2
npm ERR! message git "clone" "[email protected]:madhums/node-compress.git" "/tmp/npm-1332758574868/1332758574868-0.8424466820433736"
failed with 128
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/abhishek/nodebase/demo/npm-debug.log
npm not ok
Am able to delete articles in Safari on Mac OS x, but not in Firefox. The confirmation dialog ("'Are you really sure you want to delete this item?'") appears, but inspecting in Firebug, no DELETE message is sent to the server.
I think u did not handled the articles properly in the index.jade.
for the first time article is null hence the jade parser throws this errors .
TypeError: C:\Program Files (x86)\nodejs\nodemdb\node-express-mongoose-demo\app\views\articles\index.jade:21
19| - var name = article.user ? article.user.name : {}
20|
21| a(href="/users/"+article.user._id)= name
22| -
23| - if (article.tags)
24| - each tag in article.tags.split(',')
Cannot read property '_id' of null
I saw this demo are using S3 and Rackspace to store image. could you please add support for store image into mongodb. 👍
today i made a clone of your project and i found out some bugs/crashes:
thank you a lot
Currently it is not showing the error on invalid login and just the page refreshes clearing up the email and password field.
I would love to see CSRF protection added to this demo. It turns out that express supports it. http://expressjs.com/api.html#csrf
for some reason i seem to be getting this error [1] on starting a copy of this app. I tracked it down to
this bit of code in config/express.js
app.use(express.session({
secret: 'noobjs',
store: new mongoStore({
url: config.db,
collection : 'sessions'
})
}))
looking at the mongoStore variable in config/express.js
higher in the code we find:
, mongoStore = require('connect-mongodb')
[2]^^
I can't seem to figure out what the difference between connect-mongo and connect-mongodb. If I change the module used in the project to from connect-mongodb
to connect-mongo
the nasty error [1] goes away. From what I've been able to find the two are forks of each other, with connect-mongo
being more heavily updated. Is there a reason for choosing one over the other?
If not, I would propose changing to connect-mongo
as it seems to be used more and is updated more recently, and it doesn't produce that error [1].
To change simply replace [2] in ``config/express.js` with this:
, mongoStore = require('connect-mongo')(express)
as well as in the package.json
[1]
========================================================================================
= Please ensure that you set the default write concern for the database by setting =
= one of the options =
= =
= w: (value of > -1 or the string 'majority'), where < 1 means =
= no write acknowlegement =
= journal: true/false, wait for flush to journal before acknowlegement =
= fsync: true/false, wait for flush to file system before acknowlegement =
= =
= For backward compatibility safe is still supported and =
= allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}] =
= the default value is false which means the driver receives does not =
= return the information of the success/error of the insert/update/remove =
= =
= ex: new Db(new Server('localhost', 27017), {safe:false}) =
= =
= http://www.mongodb.org/display/DOCS/getLastError+Command =
= =
= The default of no acknowlegement will change in the very near future =
= =
= This message will disappear when the default safe is set on the driver Db =
========================================================================================```
You should modify:
$ git clone git://github.com/qed42/nodejs-express-mongoose-demo.git
To be:
$ git clone git://github.com/madhums/nodejs-express-mongoose-demo.git
In the readme
in the user model.
var UserSchema = new Schema({
name: String
, email: String
, username: String
, provider: String
, hashed_password: String
, salt: String
, facebook: {}
, twitter: {}
, github: {}
})
the , google: {}
is missing.
However, after added, it can't create the user record.
any hints?
login ->logout -> new articles
the server will always crash.....
throw exception:
Error: Can't set headers after they are sent.
at ServerResponse. (http.js:523:11)
at ServerResponse.setHeader (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/node_modules/connect/lib/patch.js:62:20)
at next (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/node_modules/connect/lib/http.js:166:13)
at pass (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:219:24)
at nextRoute (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:209:7)
at callbacks (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:274:11)
at callbacks (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/zj/Develop/NodeJS/qed42-nodejs-express-mongoose-demo-63c6fb4/node_modules/express/lib/router/index.js:277:9)
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.