Using mongoose

1-n, 1-1 https://stackoverflow.com/questions/32038793/one-to-one-relationship-with-mongoose First of all, there is a huge difference between relationships in MongoDB and those in SQL based datastores (you need to be clear about this from the get-go). Relationships in MongoDB are just representations of related data. There is no mechanism which maintains the integrity of these relationships. What mongoose does with […]

Using mongo via terminal for DB manipulation

$ mongo MongoDB shell version: 3.0.4 connecting to: test > show dbs bookAPI 0.078GB local 0.078GB my_database_name 0.078GB CREATE A DATABASE Don’t worry about “connecting to” … that’s just the default database Mongo decides to use if you don’t specify one on the command line, which we didn’t because it’s not important right now. It […]

Using Gulp and Nodemon

npm init then insert project info npm install express touch app.js

Let’s install it where it save info into the project json file: npm install gulp –save npm install gulp -g npm install gulp-nodemon for using nodemon to restart the server whenever you make a change: npm install -g nodemon Installing nodemon basically means […]

Install MongoDB on Mac

ref – http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/ Moving files First download the mongo database file from its website. Be default, your mac should put it into your ~/Download folder. Then open up a terminal. You cd into the download directory. Then you unzip the tgz file. Then you move the folder into directory /usr/local/mongdb cd ~/Download $ tar xzf […]

sample

“article” is related to “section”, but is distinctly different. Whereas is for grouping distinct sections of content or functionality, is for containing related individual standalone pieces of content, such as individual blog posts, videos, images or news items. Think of it this way – if you have a number of items of content, each of […]

Writing own middleware module

Standard files app.js

public/index.html

public/client.js

Writing custom middleware use request.url and request.method to get request info

The response object emits events, including ‘finish’. Which means that the response has been handed off to you.

Use next() to go on to the next middleware layer:

Basically whenever you’ve included your […]

basic JSON data movement via node and express

install express

You will then see node_modules folder in your project directory. Inside node_modules, you’ll see express framework folder. You are now ready to use express. In your project directory, create an app.js file. Then use require function to load in the express library:

Then get the application instance by calling express(). After […]