HowTo: Install node.js on Mac Snow Leopard with Express
This is the first part of some basic howto on using node.js on Snow Leopard.
At the end of this Tutorial you will have an Expressjs App running on your Mac with the famous “hello world”.
Prerequisites:
Installed XCode (it’s also on your install DVD)
Installed Macports
Now open Terminal and go through the next steps:
1. First install node.js through macports:
$ sudo port selfupdate
$ sudo port install nodejs
2. Check install:
$ node -v
v0.2.2
3. Install Node Package Manager
3.1 Preparing your system
If using an OSX Admin user (most of you are) you are member of the admin user group.
The admin group owns /opt/local which is used by macports.
To install npm without sudo, which is highly recommended, your user must have write rights on the install folder:
$ sudo chmod -R g+w /opt/local/
Password:
3.2 Automatic installation of npm
You can use the default npm install methode:
$ curl http://npmjs.org/install.sh | sh
You should see this output:
node cli.js cache clean
npm info it worked if it ends with ok
npm info using npm@0.2.3-3
npm ok
node cli.js rm npm
npm info it worked if it ends with ok
npm info using npm@0.2.3-3
npm info uninstall safe to uninstall: npm@0.2.3-3
npm info uninstall npm@0.2.3-3 complete
npm ok
node cli.js install npm
npm info it worked if it ends with ok
npm info using npm@0.2.3-3
npm info fetch http://registry.npmjs.org/npm/-/npm@0.2.3-3.tgz
npm info install npm@0.2.3-3
npm info activate npm@0.2.3-3
npm info build Success: npm@0.2.3-3
npm ok
It worked
4. Check npm installation:
$ npm -v
0.2.3-3
5. Install expressjs using npm
$ npm install express
npm info it worked if it ends with ok
npm info using npm@0.2.3-3
npm info fetch http://registry.npmjs.org/express/-/express-1.0.0rc3.tgz
npm info fetch http://registry.npmjs.org/connect/-/connect-0.2.5.tgz
npm info install express@1.0.0rc3
npm info install connect@0.2.5
npm info activate express@1.0.0rc3
npm info activate connect@0.2.5
npm info build Success: express@1.0.0rc3
npm info build Success: connect@0.2.5
npm ok
6. Now it’s time for your reward:
6.1 Create a folder for your test:
$ mkdir -p ~/nodes/express_reward/
$ cd ~/nodes/express_reward/
6.2 Create your first application
Create a file called app.js and insert the code from the expressjs homepage.
If you have installed Textmate on your system:
$ mate app.js
Insert into file:
var app = require('express').createServer();
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(3000);
6.3 Save your file
6.4 Back in Terminal start your app:
$ node app.js
7. Finished. You got node.js running and built your “Hello World” Express app
Now open: http://localhost:3000/ in browser:
Have fun with node.js and built your first express application.
Find more info at:
- http://nodejs.org/api.html
- http://github.com/isaacs/npm
- http://expressjs.com/guide.html