That's right. I said it: Always use Node, no matter what! Even if your server isn't going to be a Node server, just have it installed because you'll use it.
Why? That's what I'm going to tell you.
Before we start...
I know there are plenty of other package managers for all the different languages out there.
I'm not saying that NodeJS is better or worse than those. I am saying that npm is freaking fantastic for HTML developers.
So let's start.
Why do I need it?
When I start an HTML project there are always different tools I need. Not just script libraries, but things like compilers, or minifiers, or just something easier than Apache and IIS to run my code locally.
Back in the day, we would have a "developer setup document" that the new person would get on day one, and work their way through it over the course of the week.
Not only was the document a pain for the person to understand most of the time, but the content became out of date pretty quickly as the technology that we used changed throughout the project.
Photo credit: jppi from morguefile.com
Enter Node and npm.
Instead, I can define my development dependencies with Node, and my setup document would be:
- Clone source code onto your local machine
- From the command line, navigate to root directory
- Build it (Post coming soon)
- Project is now running.
- Start debugging things.
That's it. The configuration is defined in the package.json file, like so:
"start": "node ./build/index.js"
You can get the full scoop on package.json files here at browsenpm.org.
Making it Easier
In the beginning, writing the file yourself is necessary but as I add dependencies, I don't want to always go into the file and tinker with it.
So, npm has a solution for that:
npm install bower --save-dev
For example, I always use Bower (I'll talk about that next time). The
--save-dev flag adds to the devDependencies section of package.json. I can just commit the file to source control, and now everyone that gets the source code can use the tools I want them to.
Not that they are installed, those tools are available to me. The tools work on Node, and Node works on all platforms.
I am platform agnostic. I win. Roll credits.
The point is simple: use a package manager. If not npm, then something that works for you and your project. Many people seem to skip Node, but as an HTML developer Node and the npm can easily keep your dev environments in sync, regardless of operating system.
Oh, I skipped over Bower on purpose. That's coming next time.
Thanks for Playing. ~ DW