PACE OF CHANGE AND DEBUGGING BOOKS

I started reading the book “Pro AngularJS” written by Adam Freeman.  This book was published on April 1st 2014.  I’ve read Freeman’s books before (Pro ASP.NET MVC X) and found them to be informative.

I followed the instructions in Chapter 1 for “How Do You Set Up Your Development Environment”, which basically entails using nodejs as a simple web server for hosting your angular and bootstrap files.

So I install node, install the connect module,  copy in the simple server.js code shown here:

var connect = require('connect');

connect.createServer(
    connect.static("../angularjs")

).listen(5000);

I  run node server.js and I get  “TypeError: Object function createServer(), has no method ‘static’”

TypeError

Well, after a bit of investigation, it appears that the connect module has been reorganized, the author most likely used version 2.x, but looking at the connect module release history, version 3.0 was released on 5/29/2014. In fact the release candidate for 3.0 first appeared to be published in March, so that explains why the book doesn’t use the newer version.

To fix so it works with v3.0 of the connect module, also install the module ‘serve-static’ using the command

npm install serve-static

The replacement code that works is as follows:

var connect = require('connect')
var serveStatic = require('serve-static')

var app = connect();

app.use(serveStatic('../angularjs'));

app.listen(5000);

Alternatively, you can install an older version of connect. Looking over the history indicates that 2.13.0 would most likely be the best choice.

npm install connect@2.13.0

So far I’ve learned a bit about node, installing older versions of packages and the changes to the connect module without even reading much of the book 🙂

Hopefully the rest of the examples in the book run with less research!

2 thoughts on “PACE OF CHANGE AND DEBUGGING BOOKS”

  1. thanks for it

    András

    I found little typo:
    npm install serve-static
    instead of
    npm install server-static

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

OR

LOGIN OR REGISTER

Registered users with one approved comment can comment without moderation