Welcome to part 23 of Let’s Make a Web App, a tutorial series about building a web app with Node. This series will walk you through the major areas you’ll need to face when building your own applications. These tutorials are tagged with lmawa.
- Part 1: Introduction
- Part 2: Installation and Skeleton App, source code commit: 4ea936b
- Part 3: RESTful Methods and Testing, source code commit: 39e66cb
- Part 4: Templates, Partials, Creating and Editing Documents, source code commit: f66fdb
- Part 5: Authentication, Sessions, Access Control Middleware, source code commit: 03fe9b
- Part 6: Interface Basics, source code commit: f2261c
- Part 7: Node Library Versions, Jade Tricks, Error Pages, source code commit: 929f5
- Part 8: Flash Messages and Helpers, source code commit: 841a49
- Part 9: Remember Me, source code commit: 1904c
- Part 10: Markdown, source code commit: 11d33
- Part 11: Better Testing, source code commit: 6a269ce
- Part 12: Updating Mongoose, source code commit: 2a8725
- Part 13: Stylus, source code commit: 0a70e40
- Part 14: Email, source code commit: 2e81a7b
- Part 15: Node Versions, npm Publishing, source code commit: 89abea1
- Part 16: Updating to Node 0.4.2 and Express 2, source code commit: 19fbb2
- Part 17: UI Improvements, source code commit: 5c5fb5c
- Part 18: Full Text Search, source code commit: ceb9b32
- Part 19: Backbone.js, source code commit: 8e86240
- Part 20: Backbone.js Persistence, source code commit: 7d5cc3d
- Part 21: Connection Management, source code commit: 2fde220
- Part 22: Searching with Backbone.js, source code commit: 2b8e083
I upgraded to npm 1.0.3 recently. It generated a list of packages that were incompatible, I haven’t bothered reinstalling them yet.
Isaac’s installation instructions seem to have solidified at:
curl http://npmjs.org/install.sh | sh
… but read the npm README before doing anything!
Changes in Nodepad
It takes a while to get used to npm 1.x, but I like the changes. A big change is the default installation path: running
npm install package will install package in the local
What this means for Nodepad is we no-longer need the
I’ve updated Nodepad to work with npm 1.0: commit 52e6b1.
From Nodepad’s directory, running
npm install will build and install the dependencies to
./node_modules. That means it’s completely self-contained from everything else on your system. Running
npm -g install will install all of the dependencies in
NODE_PATH/nodepad/ — again, making the dependencies self-contained.
Using Nodepad is now fairly simple:
$ git clone git://github.com/alexyoung/nodepad.git $ cd nodepad $ npm install $ mongod $ node app.js
This is very similar to how
npm bundle used to work. When using Express apps written by other people, their documentation may suggest running
npm bundle, but
npm install should work.
Search vs. List
npm ls command used to search available packages. It now lists local packages:
$ npm ls -g ├─┬ email@example.com │ ├── firstname.lastname@example.org │ ├── email@example.com │ └── firstname.lastname@example.org ├── email@example.com ├── firstname.lastname@example.org ├── email@example.com ├── firstname.lastname@example.org
npm search will search remote packages:
$ npm search nodepad nodepad A notepad written with Node =alexyoung
Why the Change?
Isaac has been blogging and discussing npm 1.0 for some time on the Node blog and npm discussion group. A major contributing factor is Node’s 0.4 changes to the module loading system. These changes were mentioned in the Node 0.4 announcement:
require()now has a primitive understanding of package.json. It looks for the main script. This allows require() to work on package directories directly.
A specially named directory, node_modules/, is searched in the current directory for any modules. This will hopefully encourage programmers to bundle modules rather than rely on a global namespace.
It might feel awkward to have to adapt existing applications to work with npm 1.0, but the changes should be minimal and should make module management easier for everyone.