Part 1: Setting the environment ….

A few days ago I finished a simple application tweetland.com.ar I made in order to learn more about Node.js and MongoDB … on the road I also came across Socket.IO which is a great library for real time applications.
The first is to prepare the environment. To do this first download node.js (from node.js ), after downloading the installation follows the traditional steps:

1
2
3
./configure  
make  
make install \*

* the last step as root
Once installed, continue with the installation of modules. For this node has npm (which is Node Package Manager) that allows us to install the modules with a single command install npm . Instructions for installing npm are in your home page, also I leave

curl http://npmjs.org/install.sh | sh

At this time we have installed both node.js as its package manager npm. Usually what I usually do is create a directory in my case I call nodeapps as workspace.
Entering the same:

1
cd "path to nodeapps"  

and within it begin to install the modules you require. This is important because when you install the modules npm node_modules create the directory (if not there before), and install the modules in that directory.
This is important because when we do within our code something like:

1
var sys = require('sys');  

node will automatically search the directory sys module within node_modules in the current directory and not finding it will continue with the search recursively upwards, which is always important to remember where you installed the modules that we use.

Before going further make the installation of some modules used, these are express, socket.io, mongoose.

And this is precisely the last module we will use to interact with our database MongoDB, which is an object-oriented database (JSON), high performance and scalable. (in another post I will explain a little more how it works because it is a relatively new and very interesting).
To install you have to download the appropriate version from download , and once discharged, proceed to decompress

 pepo@sokol:~/DESARROLLO/POSTS/node_socket_mongo$ wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.2.tgz

2012-02-28 11:42:19 (1.06 MB/s) - `mongodb-linux-i686-2.0.2.tgz’ saved [3815722738157227]

pepo@sokol:~/DESARROLLO/POSTS/node_socket_mongo$ tar -xzf mongodb-linux-i686-2.0.2.tgz

Once unpacked and could start the service mongod and start, but I’d rather create the directory structure I will use my base, create two directories for data and logs, the first store the files of the database and the second of logs. I also create the configuration file with which I will start the service, in my case is as follows:

1
2
3
4
5
6
7
cat mongod.config   
  
dbpath = /home/pepo/nodeapps/data/  
logpath =/home/pepo/nodeapps/logs/mongodb.log  
bind\_ip = 127.0.0.1  
noauth = true   
verbose = true   

 Bind_ip option is set to only listen on localhost requests (since by default it does on all interfaces) and indicate that we will not configure the authentication and verbose.

To start the service simply run:

1
bin/mongod --config mongod.config \*  

* Inside the unzipped directory MongoDB

we see something like this:

1
2
 # mongodb-linux-i686-2.0.2/bin/mongod --config mongod.config   
all output going to: ./logs/mongodb.log  

Finally to test the service entered as follows (always from the binary directory MongoDB):

1
2
3
4
5
pepo@sokol:bin$ ./mongo  
MongoDB shell version: 2.0.2  
connecting to: test  
\> show dbs  
local    (empty)  

Well, with this we have our environment set up and configured to start programming applications in node.js with MongoDB, but that will be for the next post….

prettyPrint();