# express-comment

> Express simple article post/comment/response system middleware

Latest version **0.1.2** (published 2018-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-comment
pnpm add express-comment
yarn add express-comment
bun add express-comment
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2018-03-28 |
| First published | 2018-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 59.4 KB |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| Author | Kevin Qian |
| Maintainers | kevinkassimo |
| Keywords | express, middleware, comment, post, response |

## Links

- npm: https://www.npmjs.com/package/express-comment
- npm.io page: https://npm.io/package/express-comment

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [mysql2](https://npm.io/package/mysql2.md) ^1.5.3
- [express](https://npm.io/package/express.md) ^4.16.3
- [mongodb](https://npm.io/package/mongodb.md) ^3.0.4
- [sequelize](https://npm.io/package/sequelize.md) ^4.37.4
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.2

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2018-03-28
- 0.1.1 — 2018-03-28
- 0.1.0 — 2018-03-28
- 0.0.3 — 2018-03-24
- 0.0.2 — 2018-03-24
- 0.0.1 — 2018-03-21

## README

# `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`](https://npmjs.com/package/express-comment-frontend) as frontend API and [`/lib/api.md`](/lib/api.md) for details, and [`/example/*`](/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
```javascript
// 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
```javascript
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!
```

---
_Source: https://npm.io/package/express-comment · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
