Skip to main content

Backend Integration

For easy integration with Node.js + Express + MongoDB applications, Replyke provides a library to simplify the process for you. Follow these simple steps to integrate Replyke's backend features seamlessly into your Express application.

Installation

First, install the replyke-express package via npm:

npm install replyke-express

Setup

To use the routes provided by replyke-express, import and configure them in your Express application.

Basic Setup

  1. Import and Initialize: Start by importing the necessary modules and initializing your Express app.
const express = require('express');
const { replykeRoutes } = require('replyke-express');

const app = express();
  1. Middleware Configuration: Use the JSON middleware and configure the Replyke routes.
app.use(express.json());
app.use(replykeRoutes);
  1. Start the Server: Finally, start your Express server.
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

Example Integration

Below is a complete example of how to integrate replyke-express in an Express application, including MongoDB connection setup.

const express = require('express');
const mongoose = require('mongoose');
const { replykeRoutes } = require('replyke-express');

const app = express();

// Connect to MongoDB
mongoose.connect('your-mongodb-uri');

app.use(express.json());

// Use the Replyke routes
app.use(replykeRoutes);

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

Collections

The documents will be stored in the following MongoDB collections:

  • replyke-articles: Stores articles along with their associated likes, comments, and replies.
  • replyke-comments: Stores comments related to articles.