parthsahani-newsflow-utils
v1.0.0
Published
Utility functions for NewsFlow backend
Maintainers
Readme
NewsFlow Utils
Utility functions for NewsFlow MERN application backend.
Installation
npm install newsflow-utilsUsage
JWT Helper
const { generateToken, verifyToken, createVerifyMiddleware } = require('newsflow-utils');
const token = generateToken(userId, process.env.JWT_SECRET);
app.use('/api/protected', createVerifyMiddleware(process.env.JWT_SECRET));Password Helper
const { hashPassword, comparePassword } = require('newsflow-utils');
const hashed = await hashPassword('mypassword');
const isMatch = await comparePassword('mypassword', hashed);Response Helper
const { sendSuccess, sendError } = require('newsflow-utils');
sendSuccess(res, 200, 'Login successful', { token, userId });
sendError(res, 400, 'Invalid credentials');License
MIT
