3

Evaluating Nodejs and trying to see if it will fit our needs. Coming from a rails world, I have a few unanswered questions despite searching for a long time.

  1. Whats the best way to manage assets with Nodejs (Expressjs)? In rails, the static assets are a) fingerprinted for caching forever b) js and css are minified 3) scss is compiled down to css

  2. Whats the best way to handled uploaded images from users such as avatars?

  3. Does grunt help with minifying and gzipping html/css/javascript?

  4. How can I avoid mutliple http requests to the server with Node. I don't want to make multiple http requests for every javascript asset I need. Rails helps here by combining all js and css files.

  5. Also, is Mongodb the preferred solution for most projects? I hear a lot of bad things about Mongodb and good things about it. Having a difficult time deciding if Mongo can help with more reads than writes with probably 400-500 GB data in the long run.

Any help or pointers? Thanks so much for taking the time to point me to the right places.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
sat
  • 5,489
  • 10
  • 63
  • 81

1 Answers1

6

For each of the point you mentioned I give you a few module examples that might fit your need. Remember that at every point there are much more modules serving the same purpose:

  1. node-static (as a static file server), node-uglify (for minifying JS code), css-clean (same for CSS), merge-js, sqwish, and jake can help you with the building of the website (in this step you could plug-in the previous modules)

  2. node-formidable is pretty famous

  3. check out this question

  4. checkout this question

  5. I am not sure if it is the "preferred". It is the noSQL and the Javascript nature in it that makes it attractive. There are modules already for every type of database. ongo should handle that data. Depends also how large is one document. There are some limitations.

There is this Github Wiki page in the NodeJS project listing and categorizing many of the important modules out there.

The exact choice of modules also depends what framework will you use use to build the app. A pretty established (but certainly not the only one) is express. But you can find more on this topic here.

Community
  • 1
  • 1
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
  • 1
    Thank so much! Is there a way to manage the assets (combining, minifying, fingerprinting, compressing) at compile time rather than run time? I prefer to have them all done at compile time and avoid doing it at runtime if possible (sorry maybe I am too rails-ish in thinking) – sat May 18 '13 at 18:26
  • This was just a fast brainstorming. I am sure many other can add more modules and tools. But many are biased toward what they use (like I am when I pointed you to the above ones.) Remember that for every single feature you want, you have plenty of alternatives. – Gabriel Petrovay May 18 '13 at 18:28
  • Both UglifyJS and clean-css have command line tools that you can plug into your system on release and have them do the job. (And, there is no compile time: develop -> run; in your case: develop -> minify/combine/uglify -> run) – Gabriel Petrovay May 18 '13 at 18:34
  • Thanks again! I will try out some of these modules to see if they fit. If we fingerprint/minify/gzip on the fly (as some of these modules do), do they do so everytime or just the first time? – sat May 18 '13 at 18:42
  • I cannot give an answer to this. Not from what I know (from what I have used). We have always pre-minified them on the production servers. – Gabriel Petrovay May 18 '13 at 18:53
  • Can you please share what tools you use to pre-minify (is it uglify?) and what your deploy tools of choice are? Do you use grunt to automate all of this? We are used to doing it with Capistrano and rake tasks currently but I don't know what the parellel in tne node world is. – sat May 18 '13 at 19:29
  • Yes, grunt is good tool for it. We don't use it because our process is different in our "in house" (closed source) framework. For our purposes we use UglifyJs and clean-css and node's native zlib to perform the required task on the fly on the first request for an asset. – Gabriel Petrovay May 18 '13 at 19:41
  • You might want to check out [assetmanager](https://github.com/ReedD/node-assetmanager) there is a full example on git hub but basically how it works is you put all the file paths you want to include in a JSON file and it will swap production and development assets in and out of your layouts for you. [MEAN Stack](https://github.com/linnovate/mean) uses it too. – ReedD Jun 14 '14 at 17:22