NodeJS and Express
By Dan Baker, published 2010-09-09
So, now that nodejs is installed and running, it's time to start using it. I've heard that "Express" is super-awesome, so I walked through the page at nodeknockout, and this is what I did:- Install Express
- $ curl http://expressjs.com/install.sh | sh
- This will install express and connect into a hidden folder at [USER]/.node_libraries/
- It looks like node packages installed in this special area can be referenced as if they are "base" packages -- var express = require("express")
- Create a simple "Express App"
- Create a new folder somewhere, with a file called "app.js"
- Edit app.js with the following text:
- Note: On my cygwin install, I had to specify a port# for the app.listen(), or it threw an exception
- Run this new nodejs express app: $ node app.js
- View in the browser at localhost
var express = require("express"); var app = express.createServer(); app.use(express.logger()); app.get("/", function(req, res){ res.send("Hello World"); }); app.listen(8124); console.log("Express server started on port %s", app.address().port);