node-comment

A simple comment system

npm install node-comment
1 downloads in the last day
21 downloads in the last week
41 downloads in the last month

What is it?

Comment is a simple comment system

it use actually mongodb (others db should provided soon)

Intall

To install, run:

npm install node-comment

Usage

var comment = require('node-comment')();
/** 
  default:
    port: 27017
    host: '127.0.0.1'
    database: 'Comments'
    options: { safe: true }

  you can overhide this params like this:
    var comment = require('node-comment')({database: 'mydatabase', host: '127.0.0.2'});
**/

Adding a comment

comment.add({
  thread: 'What a usefull module!',
  content: 'yes, its my first one :)',
  author: 'xulien', // optionnal
  ip: '127.0.0.1', // optionnal
  whatYouWant: xxx // optionnal too...
  ...
  }, function(err) {
    /* store as in mongodb
      { 
        "thread" : "What a usefull module!",
        "content" : "soooo great!!!",
        "author": "xulien",
        "ip": "127.0.0.1"
        "index" : 1364413909942, // timestamp is used as an identifier <-----------|
        "_id" : ObjectId("51534dd5600a27675c000001")                               |
      }                                                                            |
    */                                                                             |
  });                                                                              |
                                                                                   |
comment.add({                                                                      |
  thread: 'What a usefull module!',                                                |
  content: 'Dooooohhh !',                                                          |
  author: 'homer',                                                                 |
  ip: '127.0.0.2',                                                                 |
  }, function(err) {})                                                             |
                                                                                   |
comment.add({                                                                      |
  thread: 'What a usefull module!',                                                |
  content: 'best module i have seen',                                              |
  author: 'laure',                                                                 |
  ip: '127.0.0.4',                                                                 |
  parent: '1364413909942' // optionnal, used for tree stucture <-------------------|
  }, function(err) {});

Get all comments by thread

=Thread is made by two passes=

Firstly, comments are sorted by timestamp. Secondly, child are move after parent.

we stored 1-2-3, and we got 1-3-2 with 3 child of 1

comment.get('What a usefull module!', function(err, thread){
  /* thread return
    [
      { 
        "thread" : "What a usefull module!",
        "content" : "soooo great!!!",
        "author": "xulien",
        "ip": "127.0.0.1"
        "index" : 1364413909942,
        "_id" : ObjectId("51534dd5600a27675c000001") 
      },
      { 
        "thread" : "What a usefull module!",
        content: 'best module i have seen',
        author: 'laure',
        ip: '127.0.0.4',
        parent: '1364413909942' // optionnal, used for tree stucture
        "index" : 1364413910025,
        "_id" : ObjectId("51534dd5600a27675c000001") 
      },
      { 
        "thread" : "What a usefull module!",
        content: 'Dooooohhh !',
        author: 'homer',
        ip: '127.0.0.2',
        "index" : 1364413910024,
        "_id" : ObjectId("51534dd5600a27675c000001") 
      }
    ]
  */
});
npm loves you