I usually use the node-static module (
https://github.com/cloudhead/node-static) for serving static files; I've 
had good success with it so far.

I usually put all the static files in a tree of folders underneath one 
'public' folder, but I suppose you could call it 'assets' or whatever you 
like.

For instance, to serve all JSON requests dynamically and to serve 
everything else as static files, you could do something like this:

var static = require('node-static');
var fileServer = new static.Server('./public', { cache: false });

http.createServer(function(req, res) {
  if (req.url.test(/\.json$/i)) {
    // serve JSON requests dynamically here
  }
  else {
    // serve everything else statically
    fileServer.serve(req, res);
  }
}).listen(8080);

Of course, it's even easier if you're using a framework like Express, which 
has a static file server built-in, but if you prefer "small and sharp" 
modules, I recommend node-static (though I'm sure there are other 
high-quality options out there too, like https://github.com/isaacs/st).

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to