Webapplication/-site structure with express.js and restify.js

203 views
Skip to first unread message

Manuel Schoebel

unread,
Oct 17, 2012, 4:13:30 PM10/17/12
to nod...@googlegroups.com
Hi, i am playing with node.js for a little while now and ran in an issue i want to adress. For this i would like to get some advice.

First: I'm building a website (it is more a test-project where i'd like to test and learn some things, so it is okay for me if i "overcomplicate" things). On the website there is also a blog. I also build a little admin interface. The admin interface will be its own node.js app. So i have the website and website-admin as two independent projects.

I use express.js and mongoose.

The "Problem": 
I tried to share the models of the website with the admin but this does not work. If i try to get some data in the admin via the websites models, i do not get any reaction from mongoose, not even an error. As i read somewhere the models cannot be shared between apps. One option would be to copy the models into the admin-app. But i do not really like this approach.

What i want to do:
So i am thinking to separate the models and whole db into a third app. An api with restify.js. So the website and the admin can use the api and i would only have the models in one place. The glue between all would be node-proxy (somehow, i am not exactly sure how to do this right now ;).

Is there a better way to share the models if i want to separate the admin and the website as its own node-apps? Does this sound stupid to you? Why?

Best regards
Manuel

Daniel Rinehart

unread,
Oct 17, 2012, 9:51:56 PM10/17/12
to nod...@googlegroups.com
Something to quickly check, if you are not getting any reaction from
mongoose in the admin site using the same models, have you ensured
that you are initializing the mongo connection in the admin. Mongoose
will queue commands until a connection is established.

One approach that I've used it to create a private module with just
the models that both the web site and admin site can use. With "npm
link" you can set it up locally and then only "copy" on deploy.

-- Daniel R. <dan...@neophi.com> [http://danielr.neophi.com/]
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

greelgorke

unread,
Oct 18, 2012, 3:53:41 AM10/18/12
to nod...@googlegroups.com
+1 for packaging out the shared code. this is how node handle code re-usage at all

Manuel Schoebel

unread,
Oct 19, 2012, 3:06:07 AM10/19/12
to nod...@googlegroups.com
Yes i initialized the mongo connection. I also checked the connection with the connected event.

The tip with "npm link" sounds good, i will try this. Thanks a lot!


Am Donnerstag, 18. Oktober 2012 03:52:11 UTC+2 schrieb Daniel R.:
Reply all
Reply to author
Forward
0 new messages