Giter Club home page Giter Club logo

express-comment's Introduction

express-comment Simple Article Post/Comment Management Middleware

express-comment is a middleware bundled with frontend API utilities that allows you to create a simple yet highly usable post/comment system with minimal code.

Condition

This package is under active development, and is just entering its alpha stage. The API may change with new features added in the future.

How to use

Install express-comment-frontend as frontend API and /lib/api.md for details, and /example/* for examples of backend use. In general, you can simply mount the middleware on a path with minimal configuration, and use /lib/frontend predefined API for simple query and update.

Demo

Front-end API

// frontend code, using lib/index.js of express-comment-frontend
let comment = commentFactory(window, '/api/express-comment/mounted/path');

// If you use React/Node instead, you can likely to be able to simply (not yet tested)
import commentFactory from 'express-comment-frontend';
let comment = commentFactory(window, '/api/express-comment/mounted/path');

// begin:

let commentID;
let replyID;

// Callback styled
comment
  .comment('Hello world')
  .by('Kevin')
  .on('Article-01')
  .fire((err, id) => {
    if (err) throw err;
    commentID = id;
  });

// Promise styled
comment
  .reply('This is a reply!')
  .by('Tom')
  .to(commentID)
  .fire()
  .then((id) => replyID = id)
  .catch((err) => console.log('ERROR!', err));

comment
  .update('I want this as reply body instead!')
  .of(replyID)
  .fire();

comment
  .findAll(true) // true if you want to get all replies to the comment found, will be accessible at entry[i].reply
  .of(commentID)
  .fire()
  .then(console.log);

// find root comments on an article
comment
  .findRootAll() // true if you want to get all replies to the comment found, will be accessible at entry[i].reply
  .on('Article-01')
  .fire()
  .then(console.log);

// Delete!
comment
  .delete()
  .by('Tom')
  .fire()
  .then(() => console.log('Sadly, Tom\'s replies are deleted...'))
  .catch((err) => console.log('ERROR!', err));

comment
  .delete()
  .of(commentID)
  .fire()
  .then(() => console.log('Sadly, Kevin\'s first comment is deleted...'))
  .catch((err) => console.log('ERROR!', err));

Back-end API

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const comment = require('express-comment');
const drivers = comment.drivers;

// General settings
const ecSettings = {}

// with MongoDB (Mongo Native Client)
const mongo_config = {
  /* ... */
  // see /lib/db/mongo/README.md
};
app.use('/api/express-comment/mounted/path', bodyParser.urlencoded({ extended: true }), comment(drivers.mongo(mongo_config), ecSettings));

// or if with Sequelize.js (supporting MySQL, PostgreSQL, SQLite, etc.)
const sequelize_config = {
  database: 'ec',
  username: 'root',
  password: '',
  settings: {
    /* Sequelize config settings, check Sequelize docs about config settings. */
    host: 'localhost',
    dialect: 'mysql',

    pool: {
      max: 5,
      min: 0,
      acquire: 30000,
      idle: 10000
    },
  }
}
app.use('/path/middleware/mounted', bodyParser.urlencoded({ extended: true }), comment(drivers.sql(sequelize_config), ecSettings));

/* ... */

// You are good to go!

express-comment's People

Contributors

kevinkassimo avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.