A little project with Node.js, MongoDB, Jade and Stylus
Although I like to consider myself more of a coder than a designer, I'm quite proud of interiordelight.ro, the last little project I've managed to put together using what I'm beginning to believe is the "killer combination" in the Node.js ecosystem:
- Server-side coding in IcedCoffeeScript for simple yet powerful asynchronous control flow - see this old post for more info;
- Storing data with Mongoose in MongoDB;
- customised markdown processing with marked;
- Jade templates;
- Stylus as a robust CSS preprocessor, which was very helpful for building a flexible, mobile-friendly layout without using a "heavy" UI framework;
- Client-side assets packaged with ASPAX.
During the development of this little project I've learned a few new things that I'd like to share with you here in a few tips, so... stay tuned!... ;-)
Written by Ionut-Cristian Florescu
Related protips
8 Responses
Here's the first tip: Using dynamically resized-images from Google+
...and a 2nd one about a quick & dirty fix for the infamous Safari blank-page bug
Do you mind providing some insight into your infrastructure (hosting mainly)? Can you suggest some providers, maybe give some tips on things to look for (eg. installing node modules) as well as your opinions on services you may have tried. Thanks for the great info, and I agree that nodejs + mongodb is the next thing.
@designbyonyx - thank you for reading my post, Ryan!
In relation to hosting infrastructure, I've tried Heroku, AppFog and I've played around a bit with OpenShift.
Each one has its own pros and cons, but I can safely say my number one favourite is Heroku by far. Not the cheapest, but it's safe, reliable, you can run any Node.js version you like, it has a nice git-based deployment mechanism with the possibility to do rollbacks if necessary, and you can also choose among an infinity of add-ons for your apps. Plus, their now standard Node.js buildpack has a fantastic caching mechanism that will only download and install the necessary NPMs in your server environment (which means really fast deployments).
I'm not sure I understand what you mean by tips on "installing node modules". If they're on npmjs or github, Heroku will install them automatically based on package.json
. But on most PaaS providers you can deploy your node_modules
folder anyway. If your modules use native code, they might have to be compiled on the deployment environment, but again most PaaS deployment mechanisms will do it behind-the-scenes based on node-gyp
.
If we're talking about "standard" web projects (tens to hundreds of concurrent users), there aren't many things you can't do with clustering and 1-2 Heroku web workers. For larger projects, scaling is pretty straightforward, but it also depends on your app architecture.
In relation to MongoDB, I like both MongoLab and MongoHQ.
RedHat's OpenShift is also interesting as a "general purpose" PaaS provider, you can do lots of things with it, but you'll have to do a bit of command-line hacking and configuration if you want to install a particular Node.js version for instance. But they do offer you 3 free boxes to start with...
Thanks for the thorough response! Heroku seems to be a favorite in the node community, but it is my understanding that you can't work with web sockets on Heroku. Any experience there?
Also, with more "classical" hosting you often aren't allowed SSH access (unless you pay more) which is required for "installing node modules" or anything else which requires the command line. Being that NPM and the command line is such an integral part of working with node, I was curious as to how this worked with a hosting provider. The npm/git integration seems to solve many of these issues.
OpenShift really seems to be a neat thing and appears to be exactly what I was looking for - SSH, node, and MongoDB. I really appreciate all the great info!
@designbyonyx You're welcome, Ryan!
I haven't used web sockets yet in my apps and I know people were complaining about it on Heroku, but I understood they fixed it in late 2013. See this stackoverflow thread here, the guy has a basic example running on Heroku.
Also, heroku run bash
will give you console access.
I hate Jade, things quickly run out of hand with Jade.
Care to elaborate on this for me?