Deploy a Framework Friday #3 with node.js + express.js

Time for the node.js “Deploy a Framework Friday”. First get node.js and express.js installed (i.e. npm install express) and then create your node.js application.

[sourcecode language=”bash”]
adron$ express nodejs

create : nodejs
create : nodejs/package.json
create : nodejs/app.js
create : nodejs/public
create : nodejs/public/javascripts
create : nodejs/public/images
create : nodejs/public/stylesheets
create : nodejs/public/stylesheets/style.css
create : nodejs/routes
create : nodejs/routes/index.js
create : nodejs/views
create : nodejs/views/layout.jade
create : nodejs/views/index.jade

dont forget to install dependencies:
$ cd nodejs && npm install
[/sourcecode]

Once the app is installed open up the app.js file and edit the code so that it reflects what is shown below.

[sourcecode language=”javascript”]
var express = require(‘express’)
, routes = require(‘./routes’);

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
app.set(‘views’, __dirname + ‘/views’);
app.set(‘view engine’, ‘jade’);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + ‘/public’));
});

app.configure(‘development’, function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure(‘production’, function(){
app.use(express.errorHandler());
});

// Routes

app.get(‘/’, routes.index);

// Cloud Foundry Environment Variables
var port = (process.env.VMC_APP_PORT || 3000);

app.listen(port);
console.log("Cloud Foundry Demo Express server listening on port %d in %s mode.", app.address().port, app.settings.env);
[/sourcecode]

The emphasis is the port variable added for the VMC_APP_PORT. This variable is needed by the Cloud Foundry system to know which port that node will use to host on, which Cloud Foundry will then intelligently map to so you will get the standard default port 80 activity you expect. For more information about all this hosting mess with node.js check out one of my previous write ups on the topic on the New Relic Blog.

Once you’ve setup this file, then just deploy using the with npm support option that states the version of node.

[sourcecode language=”bash”]
vmc push –version=node06
[/sourcecode]

For more information about deploying node apps with npm module dependencies check out this blog entry on “Cloud Foundry supports node.js modules with NPM“.

All done. Yes, there is more Deploy a Framework Fridays coming up, so stay tuned!

Garann Means to Present DRYing out Your Client-side Apps @ #NodePDX

This is the second in a series of posts about the individual speakers lined up for…

I’m stoked to introduce another one of our NodePDX Conference Speakers today. Garann Means is traveling from the weird city of Austin, Texas to the weird city of Portland, Oregon so she can impart on us coders some of knowledge around “DRYing out of Client-side Apps”. As she describes,

“There’s plenty of cool stuff Node offers purely in terms of server-side architectures, but it also offers a way to solve a problem we’ve been wrestling with since client-side applications became a big deal: writing everything twice. Rather than having the templates that produce markup exist in one backend language and in JavaScript, you can reuse them. Instead of validating in JavaScript on the client for the user’s convenience and then again in some other language on the server for security, you can share a validation module that can be used in both scenarios. And so on. We’ll look at some of the ways to stop repeating ourselves in Node apps and focus on getting the most out of existing client-side code.”

Garann looking at the code to her upper right.
Garann looking at the code to her upper right.

Garann is a JavaScript Dev in Austin with her dog and cat, who leap in for code reviews. She grew to love Node after a history of backend development combined with her passion for client-side apps. She has a, and I quote “colorful” blog, which I myself read every time she posts a new entry. She’s also an author of “Node for Front-End Developers” from O’Reilly, which she wrote when she wasn’t remodeling her house and coding awesome JavaScript magic!

Garann has some seriously good reads over on her blog, some of my favorites include:

  • The 150k Solution -> Companies, especially those in sprawling suburbia need to take heed of what she writes about here, and even more so are those companies that try to throw money at developers. She’s got more insight into this than most people that are actually in charge of finding talent!
  • Calling the github API with Node.js -> This post is pretty obvious why it’s a favorite of mine. She does a deep dive into use the github API, and, well, just go check it out. Great material.

Also, Garann is active & involved on github obviously. Give her a follow on lanyrd and also on twitter.

If you’d just like to come and check out Garann’s Presentation and the other great presentations lined up, get involved in some coding, hear what Node.js is all about please RSVP and get the event on your calendar!

If you’d like to be among the presenters, submit a proposal, and you too can step up into the coder spotlight.

PDX Node.js Conference, cuz’ PDX won’t settle for not having a Node.js Conference!

Coming up really soon is the PDX Node.js Conference.  If anybody is interested in speaking, please submit a proposal. If you’d just like to attend, it is 100% free, just RSVP.

Node.js Logo
Node.js Magic Logo

Also, if anyone is interested in taking the train down to Portland, the last two departures that Friday will have a group of attendees going; Train #507 Departing at 2:20pm and #509 departing at 5:30pm from King Street Station. (Schedules)  If anyone is interested in taking the train down please let me know and I’ll help coordinate so we can all get seats (preferably with tables) to hack together while enjoying the scenery.

Core Idea

The idea behind this Node.js Conference is a technology focused, node.js, JavaScript Lib, hacker conference. We felt that there needed to be a more tech focused event around the core technologies so Troy Howard (@thoward37), Jesse Hallet (@hallettj), and I thought “we’ll just get our own thing happening” and thus, PDX Node.js Conference was born.

So check out the site, come share your JavaScript chops, Node.js hacks, favorite js libs, or just come and check out the conference and meet some smart, cool, and sexy people in Portlandia, Oregon.

Click for a massive, full size, huge panoramic shot of Portland from the Aerial Tram.
Click for a massive, full size, huge panoramic shot of Portland from the Aerial Tram.

Underscore.js and Underscore.js \m/ Lib Series Issue #001

Recently I wanted some string manipulations that just weren’t available with plain JavaScript. I went digging and came up with the Underscore.js Library. It was a little confusing at first, and the string library is an extension of Underscore.js. At first it sounded like there were two Underscore.js Libraries, but finally I got it figured out.

Get Underscore.js here:

Get the Underscore.js “Underscore.string” here: