Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Is Node.js useful for "classic" style websites?

Is Node.js useful for "classic" style websites?

Problem

I am considering using Nodejs to make a non-realtime app. For example, a website like a blog, forum, or image boards.

I have read that nodejs is good when used for asynchronous jobs. So I am wondering what the result would be when used to serve a lot of static files, like big images, css & js files, etc.

Is it true that when sending a file (suppose it's 2-3MB), the whole server will be blocked until the transfer is complete? I have also read that it might be possible to use the OS's sendfile() syscall to do this job. In this case, does Express support this?

Problem courtesy of: john smith

Solution

No it is not true. You can easily send files that are large (much larger than 2-3 MB) without blocking. People who complain about things like this blocking the Node event loop just don't know what they're doing.

You don't necessarily need to use Express to get this behavior.

That being said, if what you want is a file server, there's no reason to use NodeJS. Just point Apache at a directory, and let it fly. Why reinvent the wheel just to use the new sexy technology, when old faithful does just fine?

If you would like to use node as a simple http server, may I recommend the very simple command line module.

https://npmjs.org/package/http-server

I haven't looked at the code of the module, but it is likely not optimized for large files. Let's define large in this case, as files that are not easily cached in memory(whatever this means for your setup). If your use case calls for more optimization (piping "large" files for example) you may still have to write your own module, but this will get you started very quickly, and is an excellent utility to use for general development when you need to serve up a directory real quick.

Solution courtesy of: ChrisCM

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Is Node.js useful for "classic" style websites?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×