Saturday, 15 March 2014

node js 4 install mogodb + create nodejs project

Install mongodb, and install by simply unzip the archive.
Move mongodb to another location and configure this location into environment path:

~/.bash_profile:
export MONGODB=/Users/Peter/Documents/dev/mongodb-osx-x86_64-2.4.9

export PATH=$PATH:$MONGODB/bin
after this file is changed run:
source ~/.bash_profile.

create mongodb data folder:
create a folder by: mkdir $MONGODB/data/db

start mogodb by:

mongod -dbpath $MONGODB/data/db/

a tutorial:
http://www.mongodb.com/presentations/building-web-applications-mongodb-introduction 

mongoose vs mongojs
http://luiselizondo.net/blogs/luis-elizondo/mongoose-vs-mongojs-nodejs



------Create project 

Create a node js project with express, then configure this project by package.json:
{
  "name": "expresstest",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express"    : "~3.4.4",
    "mongoose"   : "~3.6.2",
    "hjs": "*"
  }
}

The key part is the dependencies section.  It decides which node models i will use in this project.

Run "npm install" to install models.

create core.js for Angular.js

create html.hjs for the page.

I found Hogan.js and Angular.js conflect. I have solved it by:
http://stackoverflow.com/questions/20911710/hoganjs-and-angularjs-with-nodejs
http://comments.gmane.org/gmane.comp.lang.javascript.express/1426
app.locals.delimiters = '<% %>';


















No comments:

Post a comment