Node Application Patterns: Setting up

RobC

Rob Conery teaches Node JS

Welcome to this review of the Pluralsight course Node Application Patterns by Rob Conery

Rob has been working in the technology field full time since 1998 as a DBA and then a web developer.

His original focus was the Microsoft ASP.NET stack, building tools like Subsonic and the first Micro-ORM: Massive. He co-founded the online training site Tekpub.com with James Avery and co-host This Developer’s Life with Scott Hanselman.

Tekpub was bought out by Pluralsight and he worked there for two years. He is currently working on a new book called The Imposters Handbook.

Node Applications Patterns is the final course in the Node JS learning path.

Setting up your project

Node and Grunt

Although this is the final “Advanced” course in the NodeJS learning path, this module covers Node basics and you don’t need to have seen any of the previous courses to follow along.

Rob recommends doing Node development on a Mac if you have one, or Ubuntu if you don’t.

We create a froggyfrog project, and Rob discusses why there are thousands of node repositories available on Github. Then onto Grunt:

npm install grunt-cli -g

We install grunt-contrib-jshint, a linter for Grunt.

Then Rob explains what package.json files are for and how to write a simple one.

Then we write a Gruntfile.js for running the linter.

Understanding Modules

We create a second package.json file located inside lib/utility.

All node modules are instantiated once and cached in memory for the life of the application, so each module behaves just like a singleton.

Organization

Rob recommends creating a single directory for your project and subdirectories for each module.

He uses Domain Driven Design to influence the project structure, thinking in terms of business services:

  • Accounting
  • Sales
  • Fulfillment
  • Membership

At this point in the course, we’ve already heard the unix mantra “do one thing and do it well”.

This principle drives the recursive structure of node modules and it’s important to appreciate it from the beginning. Is this design clean or messy to you? Beauty is in the eye of the beholder.

We’re beginning this project with the membership system. We will need models and processes specific to this system, and to expose these through an API in index.js

Choosing a Test Framework

Mocha is the most popular framework for Node developers, but there are many alternatives that also work well.

Rob has another course Node.js Testing Strategies that covers testing with Mocha in much more detail.

Or see the course Testing Clientside JavaScript by Joe Eames for information on QUnit, Mocha, Jasmine and Sinon.

The should assertion library is installed, and we see how to write a silly test.

Flexing Git and Github

When using Git, we should include the node_modules directory in our .gitignore file.

Rob explains the difference between local modules and those in the NPM registry and remembering to start with a . or a /

We see that adding a version property into our package.json is mandatory.

Part 3 – Building a Registration Module is coming soon

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s