반응형

Node.js, Express, MongoDB를 이용하여 REST API 만들기  http://mobicon.tistory.com/197


원문 : http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/



Installing Node.js

  1. Go to http://nodejs.org, and click the Install button.
  2. Run the installer that you just downloaded. When the installer completes, a message indicates that Node was installed at /usr/local/bin/node and npm was installed at /usr/local/bin/npm.

Installing Express

Express is a lightweight node.js web application framework. It provides the basic HTTP infrastructure that makes it easy to create REST APIs.

Installing MongoDB

To install MongoDB on your specific platform, refer to the MongoDB QuickStart. Here are some quick steps to install MongoDB on a Mac:

  1. Open a terminal window and type the following command to download the latest release:

    curl http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.2.0.tgz > ~/Downloads/mongo.tgz

    Note: You may need to adjust the version number. 2.2.0 is the latest production version at the time of this writing.

  2. Extract the files from the mongo.tgz archive:

    cd ~/Downloads
    tar -zxvf mongo.tgz

  3. Move the mongo folder to /usr/local (or another folder according to your personal preferences):

    sudo mv -n mongodb-osx-x86_64-2.2.0/ /usr/local/

  4. (Optional) Create a symbolic link to make it easier to access:

    sudo ln -s /usr/local/mongodb-osx-x86_64-2.2.0 /usr/local/mongodb

  5. Create a folder for MongoDB’s data and set the appropriate permissions:

    sudo mkdir -p /data/db
    sudo chown `id -u` /data/db

  6. Start mongodb

    cd /usr/local/mongodb
    ./bin/mongod

  7. You can also open the MongoDB Interactive Shell in another terminal window to interact with your database using a command line interface.

    cd /usr/local/mongodb
    ./bin/mongo

    Refer to the MongoDB Interactive Shell documentation for more information.

Installing the MongoDB Driver for Node.js

There are different solutions offering different levels of abstraction to access MongoDB from Node.js (For example, Mongoose and Mongolia). A comparaison of these solutions is beyond the scope of this article. In this, guide we use the native Node.js driver.

To install the the native Node.js driver, open a terminal window, cd to your nodecellar folder, and execute the following command:

npm install mongodb







.




반응형

+ Recent posts