8

I am trying to set up a static file server/cache in Node.js. I use Express.js.

Express comes in with a built-in static server, and Express is definitely one of the most used frameworks, and so one would expect the static middleware to be super reliable.

However, I look around the internet and find that tons of people, including Nodejitsu, recommend the node-static npm module.

I try to do some kind of comparative research between the two but don't find much.

Is there really any difference? I would like to use Express.static, as I am already using Express, but want to make the right choice.

This isn't an opinion war post, I am just looking for comparatives of features from those who know what they are talking about, not 'favorites'.

dthree
  • 19,847
  • 14
  • 77
  • 106
  • Do you know why folks are recommending node-static? I've never had any problems with static from Express, but I'm not generally serving anything beyond some basic resources with Node.js. – Brad Dec 03 '13 at 20:47
  • No, that's the problem, an example is here: http://blog.nodejitsu.com/6-must-have-nodejs-modules - see, its just like 'this is a great module', but it doesn't really compare to others. – dthree Dec 03 '13 at 20:48
  • It looks like `node-static` has built-in caching. Express' static doesn't as far as I know. – Brad Dec 03 '13 at 20:51
  • 3
    "want to make the right choice". Start with express since you are using it. If you were anti-express you should start with node-static. If you ever have any problems with either (unlikely IMHO), switch. Can you imagine switching taking more than 1 hour given each one needs basically a require statement and a path? Just grab one and use it. I think this is a better approach than surveying SO. If you want a survey, look at github stars, npm dependents, or whatever. My point here is the cost of making the wrong choice is very very low vs say choosing the wrong DB. Go for it. – Peter Lyons Dec 03 '13 at 20:54
  • @Brad I wonder if such a cache would make much difference, given that all modern OS'es buffer file-I/O anyway :) – robertklep Dec 03 '13 at 21:22
  • @robertklep That would be my thought as well. Depending on the use case, there would definitely be benefit, but it sounds like over-optimization for many Node use cases. – Brad Dec 03 '13 at 21:25
  • 2
    Node-static just serves static files. It's a one-function module. It's convenient, but if all you have is static files, a modern web server may be a better choice (**lots more hosts, and availability options for static sites**). Express does far more (in fact, it's Connect), and can also serve static files with an included piece of middleware. Express/Connect serves static files via the "send" npm module, which does not cache files. – WiredPrairie Dec 03 '13 at 21:42
  • @Brad, Peter, Klep, thanks for your answers. As you guessed, my main concern is the caching aspect, for example does static cache more cleverly or efficiently than express, or vice-versa? I guess its not a big deal. My Node.js server does a lot of things, and yes I use a lot of express/connect middleware. I have been battle-readying it for very high volume in the last week and this is just one piece of that. I'm building a full SPA from the ground up, front and back, by myself and server optimization isn't my highlighted specialty. – dthree Dec 03 '13 at 22:41
  • @dc2 The Express static module doesn't cache at all. Although it sounds like you need to handle caching with another module, depending on what you're doing. – Brad Dec 03 '13 at 22:45
  • Another module besides node-static? Is there something on caching that node-static doesn't handle? – dthree Dec 03 '13 at 22:53

0 Answers0