I’m sure many of you have heard about the new server side javascript project called node.js. I’ve been using myself to build full stack dynamic websites and find it a very nice environment to create a dynamic website. When I first started out I had no idea what sort of way one should create an MVC style framework with node or what modules would help me to achieve the model, view, controller ideal. Heres my stack:
- Node.js (http://nodejs.org/) of course
- NPM (http://npmjs.org/) to easily install packages for node.
- Express (http://expressjs.com/) – a very nice web development framework built on connect (allows “controllers”)
- Mongoose (http://mongoosejs.com/) – a solid orm for mongodb in node.js that just released a much improved version (allows “models”)
- Jade (http://jade-lang.com/) – a template engine for node that allows some cool shorthand (allows “views”)
- Other tools were used of course but those were the essentials.
The application directory looks something like this:
1 2 3 4 5 6 7 8 9 10 | /app-root /models /views /controllers /public /tests /scripts /logs /tmp app.js |
Inside the application I instantiate express, include my mongoose models and include my routes/controllers from the controllers directory at the bottom. Inside the controllers I call res.render to render the jade views and it all works very nicely. If people would like me to elaborate on this more let me know.
A huge shoutout and thank you to the LearnBoost guys (TJ Holowaychuk, Guillermo Rauch, Aaron Heckmann, and many more that aren’t associated with LearnBoost) who’ve made Node.js web application development a breeze.
LAMP is the web stack that powers the majority of websites today. My argument is that we are in the beginning stages of a transition away from using Linux, Apache, MySQL and PHP (there other variants) towards utilizing Node.js, a Unix based operating system and MongoDB for hosting web applications. Here’s why:
Node.js scales better and can do more with a simpler interface than Apache and PHP
The combination of apache and php to serve web sites is a threaded system. When a request comes in to apache it spawns a new thread and php renders the page. During heavy load apache’s spawning of threads can actually be the bottleneck in the system if the database is really fast. Node uses a very different system, running under Google Chrome’s V8 javascript engine it runs an event based system on one thread. It has callbacks for just about everything and the thread never needs to wait for i/o to finish before moving on to something else. During high load node excels because of this asynchronous system where it doesn’t use nearly as much memory because it does not spawn threads. (A great talk on the difference: http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html) Another thing to keep in mind is websockets are starting to gain a backing and having many requests coming into apache over websockets is not just complicated but slow.
Unix based OS
While this will probably be linux both technologies work great on FreeBSD and Apple’s OSX. This is really nothing new because there are things like wamp that exist for the lamp stack on windows. I however, cringe when someone tells me they are developing anything other than a flash or windows application on windows.
MongoDB
The NoSQL trend is gaining huge traction these days because of its extreme performance advantages. As opposed to MySQL and its other sql friends MongoDB keeps as much in memory as possible while still keeping it usable. I make this point because Redis provides the speed of memory but without the tools you would find in an sql database. Some benchmarking that proves my point: http://jayant7k.blogspot.com/2009/08/document-oriented-data-stores.html
I see a NUM future on the web, with users running real time web applications that utilize websockets. They are sending at least a factor of ten more requests per second and the lamp stack’s days are most certainly numbered
Check out my latest project: http://www.clubloc.com
Its an ongoing project of mine that’ll let you listen to music while seeing cool visualizations in canvas. I’ll be updating it soon to let users have their own playlists and share them with friends. Eventually I want it to have a chat capability that lets you meet local people and share what you’re listening to.
I side step the legal barriers to this by using a neat trick, if you can figure it out props to you.
It gets its inspiration from the notorious demo by 9emelents at: http://9elements.com/io/projects/html5/canvas/
Today while coding my first Facebook application running on Google App Engine I was getting odd errors related to time from the datastore.
The problem was that Google App Engine’s time is always running from Coordinated Universal Time (UTC), even when you use something like:
1 2 | import datetime datetime.datetime.now() |
How you should and I have compensate for this is taking the difference of the time you want to UTC time in order to shift the time to the time zone of interest:
1 2 3 4 5 | import datetime time = datetime.datetime.utcnow() - datetime.timedelta(hours = 5) # for East Coast United States time = datetime.datetime.utcnow() - datetime.timedelta(hours = 6) # for Central United States time = datetime.datetime.utcnow() - datetime.timedelta(hours = 7) # for Rocky Mountains United States time = datetime.datetime.utcnow() - datetime.timedelta(hours = 8) # for West Coast United States |
This will give you the correct time in your time zone
I got stuck this morning with an invalid sender error from my deployed Google app engine application (you can see the errrors in the log in the dashboard if it just says “Server Error” in the title tag) and I had to search around for a while for an answer.
I eventually figured it out and I’ll post my solution here just to make it easier for others:
- Make sure the email in your main settings.py is valid and yours/part of your groups.
- Also make sure that that email is included in the developers in the dashboard of the application. (https://appengine.google.com/)
- If its not:
- Log into the dashboard with the original user
- Go into the developers section and invite them to also be an administrator to the application
This simple walk through doesn’t only pertain to those that use Google app engine, it applies to all users of Google app engine.
Hopefully it will save someone some time.


