nodejs + express with jsonp example

I’ve been working more and more with nodejs and have to say I am really loving how easy it’s been to get to grips with. I’ll be posting up more about how I’m using node and the problems I’m using it to solve over the coming weeks. However I wanted to illustrate just how simple it is do something that would be more work in other languages such as PHP.

So here’s a quick example I created that illustrates how to make a simple JSONP call to a nodejs + express server.

Here’s the server side code:

and here’s the client side Html code:

To enable jsonp callback support in an ExpressJS application you just have to include the line:

app.enable(“jsonp callback”);

Once you’ve done this you can use the .json() method on the Response object to handle everything for you. So in my example above any HTTP GET request to /foo?cb=myfunction would return myfunction(“hello world”); with the Content-Type header set to text/javascript.

The Founder’s Dilemma

If entrepreneurship is a battle, most casualties stem from friendly fire or self inflicted wounds

I’ve really enjoyed reading Noam Wasserman’s ‘The Founders Dilemma: Anticipating and Avoiding the Pitfalls That Can Sink a Startup‘. This is possibly best described as book of research and case studies conducted into starting up a company from the perspective of an entrepreneur. Wasserman focuses on the key dilemmas any founder of a startup will face; these include career dilemmas, dilemmas with co-founders, acquisitions, investor dilemmas, recruitment, exit dilemmas and many others. The book analyses, quantitatively, the early decisions by entrepreneurs that can make or break a startup; what he has done here is conducted real research to get beyond anecdotes and case studies to more general patterns.

What occurred to me was that many of these dilemmas apply to any situation where a leader might be faced with building a team, finding the right people to embark on a journey together in order to achieve a shared goal. What makes this book such compelling reading are the real world examples that Wasserman cites, and the candor with which he analyses the decisions that were made and describes the real effects and consequencesĀ  of those decisions.