This npm package provides functionality for managing posts, including creating posts, fetching posts, and adding comments and adding reaction on post. It is built with Node.js, Express, and MongoDB.
To use this package in your project, you can install it via npm:
npm install post-manager
Initializing the Database Connection Before using the package functions, initialize the database connection by providing your MongoDB connection string:
const communityPackage = require('post-manager');
const mongoUrl = 'Your mongo URL';
communityPackage.initializeDatabase(mongoUrl);
const media = [{
type:'img', // 'img', 'pdf', 'video', 'gif', 'emoji', 'other'
url:"url" // Url of Media
}]
const postData = {
title:"Post Title", // Mandatory to pass
description:"Post Description", // Optional
media:media // Optional
}
const newPost = communityPackage.createPost(userId,postData);
console.log('New Post:', newPost);
const media = [{
type:'img', // 'img', 'pdf', 'video', 'gif', 'emoji', 'other'
url:"url" // Url of Media
}]
const postData = {
title:"Post Title", // Mandatory to pass
description:"Post Description", // Optional
media:media // Optional
}
const slug = "your-post-slug" // replace with your actual slug of Post
const updatePost = communityPackage.updatePost(postData,slug);
console.log('Post Updated:', updatePost);
const collection_info = {
user_collection: "users", // User Collection name
user_name: "name", // key name of user name
user_avatar: "avatar", // key name of user avatar
product_collection: "products", // product collection name
product_name: "name",
product_logo: "imgUrl",
product_slug: "slug"
}
const slug = "your-post-slug" // replace with your actual slug of Post
const Post = communityPackage.getSinglePost(collection_info,slug);
console.log('Post:', Post);
const slug = "your-post-slug" // replace with your actual slug of Post
const deletePost = communityPackage.deletePost(slug);
console.log('Post:', deletePost);
const allPosts = communityPackage.getAllPosts();
console.log('All Posts:', allPosts);
const postId = '1234567890'; // Replace with an actual post ID
const commentData = {
text:"Osm",
parent:"1234567890" // if you reply any comment then only pass the parent (comment id) other wise no need.
}
const newComment = communityPackage.addComment(postId,commentData);
console.log('New Comment:', newComment);
const commentId = '1234567890'; // Replace with an actual comment ID
const commentData = {
text:"Osm",
}
const updateComment = communityPackage.editComment(commentId,commentData);
console.log('Update Comment:', updateComment);
const commentId = '1234567890'; // Replace with an actual comment ID
const postId = '1234567890'; // Replace with an actual Post ID
const deleteComment = communityPackage.deleteComment(commentId,postId);
console.log('Delete Comment:', deleteComment);
const collection_info = {
user_collection: "users", // User Collection name
user_name: "name", // key name of user name
user_avatar: "avatar", // key name of user avatar
}
const postId = '1234567890'; // Replace with an actual Post ID
const allComment = communityPackage.allComments(collection_info,postId);
console.log('Comment:', allComment);
const postId = '1234567890'; // Replace with an actual post ID
const reactionData = {
text:"👍"
}
const newReaction = communityPackage.addReaction(postId,reactionData);
console.log('New Reaction:', newComment);
const reactionId = '1234567890'; // Replace with an actual Reaction ID
const reactionData = {
text:"👎"
}
const changeReaction = communityPackage.editReaction(reactionId,reactionData);
console.log('Change Reaction:', changeReaction);
const reactionId = '1234567890'; // Replace with an actual Reaction ID
const postId = '1234567890'; // Replace with an actual Post ID
const removeReaction = communityPackage.deleteReaction(reactionId,postId);
console.log('Remove Reaction:', removeReaction);
const collection_info = {
user_collection: "users", // User Collection name
user_name: "name", // key name of user name
user_avatar: "avatar", // key name of user avatar
}
const postId = '1234567890'; // Replace with an actual Post ID
const Reactions = communityPackage.allReactions(collection_info,postId);
console.log('Reactions:', Reactions);
const collection_info = {
user_collection: "users", // User Collection name
user_name: "name", // key name of user name
user_avatar: "avatar", // key name of user avatar
product_collection: "products", // product collection name
product_name: "name",
product_logo: "imgUrl",
product_slug: "slug"
}
const productId = '1234567890'; // Replace with an actual Post ID
const Data = communityPackage.allPostByProduct(collection_info,productId);
console.log('Data:', Data);
This package is licensed under the MIT License - see the LICENSE file for details.
Feel free to open issues for bug reports, feature requests, or any suggestions. Contributions are also welcome. Please follow the contribution guidelines.
Make sure to include the appropriate license file (e.g., LICENSE
) and create a CONTRIBUTING.md
file if you want to specify how others can contribute to your project. Update the placeholders like your-database-name
with actual details relevant to your package.