Introduction

Node.js is a very interesting server-side Javascript application framework. It is based on Google’s V8 Javascript engine and implements evented I/O, so it is blazing fast. It looks very promising for certain types of applications, mostly those that require long-running connections. This includes streaming big files, keeping persistent connections used for realtime communication (chat, games), applications using third-party web services (with long call times), etc.

There is good enough API reference available for Node.js, however it is not trivial to start development as event-based approach is quite unusual compared to commonly used thread-based networking. There are some useful blog posts with code samples available in Debuggable blog, e.g. Streaming file uploads with node.js.

However the given examples have problem — they are too far from real world problems. Take file upload as example — the code sample provided has absolutely no info on how to save the uploaded file. It is assumed that it would be trivial for the reader to figure out, however it’s not when we have to follow evented I/O approach.

In this post I’ll show example of how to save the uploaded files with Node.js. For the impatient — just grab source from github repository.

Read more...