Getting Started with Node.js

I’ve found that I like it and hate it all at the same time. Let me ramble on about my experiences with Node so far.

First, I need to say that Node.js has an awesome community. From what I can tell the community is pretty active and responsive. I haven’t seen a public smug comment referring to my ignorance of the language and it’s eco-system yet 🙂 There is also an abundance of material out there that gets you going with Node. These beginner resources out there are invaluable and a lot of people have done a really great job of piecing together what’s necessary to start a project using Node modules.

As I’ve mentioned, the eco-system is pretty vibrant. There are literally thousands of modules out there that cater to general and specific needs. Node’s package manager makes it easy to get the modules situated into your project. Dependency management is a breeze.

OK… Here is where it gets fuzzy for me. Tool support sucks! I’ve been through several IDE’s and can not find adequate tool support for Node. I know it’s because JavaScript support is hard to pull off given the nature of the language. I’ve had to lower my expectations coming from a strongly typed language background like Java. Things like code completion are just not there yet. The closest I’ve come is to set up tern in SublimeText (or VIM!) to offer me code completion as best as it can (and it’s pretty damned good). But all in all, tool support is pretty behind the curve for the general public. WebStorm sounds promising, but I already have an IntelliJ license and I’m not about to pop for another license unless I do Node work full-time 🙂

The MEAN stack is tight. I like the idea of working in JavaScript from the backend to the frontend. I like MongoDB. Express was easy to get started with and Mongoose seems to be the abstraction of choice when it comes to talking to MongoDB. Angular is, without question, an ideal UI framework. But something is missing in this setup… At least for me.

I have yet to see a comprehensive example of the MEAN stack that incorporates testing beyond simple integration tests. I really do want mocks. Depending on how you deal with callbacks, mocking may be hard to do. I want to be able to verify my code without hooking up live express.js calls that affect the data tier. I want to verify how my models work together without having a live connection to MongoDB. I also want a decent way to escape callback hell.

Truth be told, I am not skilled in the ways of effective unit testing with JavaScript or any of the modules that Node offers. But I’m not seeing that the community has centered on an approach in this area. I do see a lot of tests that introduce fake servers or do heavy integration tests across the tiers, but I’m the level of test depth seems lacking. I popped opened a number of Github projects and this pattern repeats itself over and over again. Some don’t event have tests! Thinking about it out loud, this might be an opportunity to contribute to areas where there are no tests.

That said, there are some patterns that I’m seeing in terms of components used to construct Web apps and service APIs:

  1. express – MVC, API framework
  2. mongoose – MongoDB ODM
  3. underscore – collection handling, functional stuff
  4. sinon.js – mocking, stubbing, etc..
  5. mocha.js – test runner, framework
  6. chai.js – assertions
  7. should.js – assertions +

Those are the modules that you can easily use to get up and running using one of the various samples out there. When I get more comfortable with the ins and outs of the stack, I’ll post something that captures how these pieces work together. But for now, I’m still exploring.

This brings me to my other concern. I don’t see established patterns or archetypes defined for Node.js development work and project structures. Express doesn’t mandate a project structure, but it offers one up. I’ve found that I need to tweak it to fit my needs. I imagine this is pretty common. This is a little uncomfortable to me since I’m pretty much looking for standard ways to do things. There are a few recommendations out there as to how to organize project structures, but it’s still opened. This does make it tough to orient yourself when you’re browsing other projects to see what’s going on.

Like I said earlier, I’m exploring Node and functional concepts at the same time. There is a mind shift here that needs to occur. I have not made the leap to functional thinking yet and struggle with some of the concepts beyond map/reduce/filter. I’m trying to amend my gaps by digging deeper into functional thinking in general (outside of JavaScript, Scala, Groovy, Clojure, Java 8, etc…) I need to ground myself in these concepts and work my way out. I’m hoping that I can do this in the context of Node.

All in all, I like where Node.js is going. The momentum is there, the promise is there, but the standards are not. If it is, then I do not see it and need to be pointed to any resource that can help 🙂

Anyway… More to come. I’ll probably start pushing up my stuff up to Github so that I can share code and have something concrete to talk about rather than rants about a language that I know little about.