9

Recently I started playing with node.js.

Now, every node tutorial out there states that you should start with

npm init

and then, say you want some standard server framework, say you choose express:

npm install express

but then you'll want many more things you are used to from worlds like ASP.NET.

I talk about template engines (jade) and stylesheet pre-processors (SASS).

And then they tell you "install gulp/grunt! so you can minify and uglify and run the server and so many other things automatically!"

And that means installing gulp, node-sass, and gulp-sass, and gulp-uglify, and maybe some more really cool stuff (tsd or babel, markdown etc)...

But all of those are heavy on your disk and project. Don't look for a moment and you can easily find yourself with 100MB+ disk size for that project (which hasn't even started yet!) not to mention 10000+ files since every node module brings its own dependencies, no matter that the same dependency is used by another module. And this is a very hard thing to move anywhere, let alone a web server.

Am I missing something? I don't think it's possible that so much praise is given to the node environment while such a clear flaw exists. Do I expect too much (after all I did try to use many tools at once), is there something trivial known to Node veterans to bypass this?

  • 2
    totally agree, I was amazed to see the npm tree for some front end projects. I guess in the .net world you have the same thing, but they are all compiled to binaries so you dont notice – Ewan Mar 29 '16 at 8:27
  • 2
    Unfortunately this isn't really a specific and answerable question, so it'll probably get closed soon. What I can tell you is that 1) while all of those additional tools are useful for something, tiny projects simply don't need most of them 2) all other programming frameworks with similar functionality will come with a similar amount of stuff (just look at the JRE or .NET downloads), the only difference is how much of what you need is part of the "default" distribution and how much you have to go find in other packages 3) 100 MB on your dev machine is nothing – Ixrec Mar 29 '16 at 8:29
  • 1
    @Ixrec of course its answerable, you just did (or tried to) :). But then, i could argue your claims: 1) this doesn't have to be a tiny project - consider a project with several views with their own js files and stylesheets. that's enough to make you want to have sass, cssnano and uglify. also enough to make you want express,jade and a little more. 2) I had a decent .net project that didn't become that heavy(and nowhere as many files). 3) maybe modern dev machine take this easily, but that also weighs on the server, and that's a little more concerning. Am i wrong? – Or Yaniv Mar 29 '16 at 8:47
  • 2
    @OrYaniv Indeed, you're kind of proving my point: this is the sort of issue that can be discussed, but not answered because it's just too broad and depends too heavily on exactly what projects you're doing and what dependencies you seem to need. By the way, discussions are completely fine over in chat. Or on Quora. – Ixrec Mar 29 '16 at 8:50
  • 3
    Welcome to the wonderfully bloated "all or nothing" world of node.js, which is actually not easier and not better than whatever you used before. – Traubenfuchs Mar 29 '16 at 12:39
3

The recent left-pad issue is a prime example of the problem with this tendency in Node. When you depend on too many things, all of them are prone to go ka-pow, make your project harder to debug and, for a newcomer, harder to grasp the workings of the language.

Now good Node.js programmers know to write minimalistic applications, where dependencies are concerned. The less things you depend on - the better. Need to pad strings to the left? Code it in a helper, it's 11 lines of code with the blanks. Need to number your string rows? Code it in, it's less than 100 lines of code.

Even for more complicated tasks, like project management, I'd suggest to stick to Makefiles while your project is simple enough - grunt and gulp are really, really useful for giant projects that have a lot of heavy-lifting to do. But for your SPA blog? Write a Makefile, it takes 5 minutes and you know how it works.

The temptation to just browse npm every time you need to write 3 lines of code is great, but should be resisted, whenever it's reasonable. Don't include jQuery if you have 3 DOM manipulations, don't use angular for that static promo page, do not use express for a simplistic server. But you're coding a CMS? You'd have to be crazy not to use packages like jQuery, underscore and what's not. Working with 10 collection types, 3 dbs and querying them all the time? You'd be insane not to use underscore and a few others. Just think 'do I save enough time by installing this package?' or 'Can't I just code this in for half an hour or so?'

  • 1
    On another note, does it really take 100 lines of Javascript code to add line numbers to a string? – Robert Harvey Mar 29 '16 at 17:46
  • Hahahah, I hadn't really thought of a realistic line-numbering implementation, because... I don't really see the need for such a thing to exist, let alone as a package. – BorisStoyanovv Mar 30 '16 at 12:53
  • You could probably cut that line thing in half by just letting it be opinionated. It really is a simple problem to solve. (And it's a one liner in a language like scheme, and probably python now that I think about it) – Shayne May 1 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.