sidekick-server-2
v0.1.3
Published
A reusable Node.js server library with authentication, organization management, and payment integration
Downloads
337
Maintainers
Readme
SideKick Server
A reusable Node.js server library with built-in authentication, organization management, and payment integration. Built with Express, TypeScript, and MySQL.
Features
- 🔐 Authentication System - JWT-based authentication with OTP support
- 👥 Organization Management - Multi-tenant organization structure with invitations
- 💳 Payment Integration - Razorpay integration for subscription plans
- 🌍 CORS Configuration - Flexible CORS setup
- 📧 Email Support - Nodemailer integration
- 🔌 Extensible - Add custom routes and middleware
Installation
npm install sidekick-serverPeer Dependencies
You need to install these peer dependencies in your project:
npm install express cors mysql2Quick Start
import mysql from 'mysql2/promise';
import { initSideKick } from 'sidekick-server';
import { APP_INFO_ACCOUNT_TYPE } from 'sidekick-server/dist/utils/enums.js';
// Create database connection pool
const dbPool = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'your-password',
database: 'your-database',
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
});
// Initialize SideKick server
const server = initSideKick({
database: dbPool,
appInfo: {
appName: 'My App',
appDescription: 'My awesome application',
version: '1.0.0',
CLIENT_URL: 'http://localhost:3000',
account_type_txt: {
singular: 'Team',
plural: 'Teams',
value: APP_INFO_ACCOUNT_TYPE.TEAM,
},
},
cors: {
allowedOrigins: ['http://localhost:3000', 'https://myapp.com'],
},
jwt: {
secret: 'your-jwt-secret',
expiresIn: '24h',
},
});
// Start the server
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});Configuration
SideKickConfig
| Property | Type | Required | Description |
| -------------- | --------------------- | -------- | --------------------------- |
| database | Pool | Yes | MySQL2 connection pool |
| appInfo | AppInfo | Yes | Application information |
| cors | CorsConfig | Yes | CORS configuration |
| jwt | JwtConfig | Yes | JWT configuration |
| customRoutes | CustomRoutesHandler | No | Custom route handler |
| port | number | No | Port number (for reference) |
AppInfo
{
appName: string;
appDescription: string;
version: string;
logo?: string; // SVG or image URL
primaryThemeColor?: string; // Hex color
CLIENT_URL: string; // Frontend URL
account_type_txt: {
singular: string;
plural: string;
value: typeof APP_INFO_ACCOUNT_TYPE.TEAM;
};
}Custom Routes
You can add custom routes to extend the server functionality:
const server = initSideKick({
// ... other config
customRoutes: (app) => {
app.get('/custom-endpoint', (req, res) => {
res.json({ message: 'Custom route!' });
});
app.post('/custom-action', async (req, res) => {
// Your custom logic
res.json({ success: true });
});
},
});Built-in Routes
The library includes the following routes:
Public Routes (No Authentication Required)
POST /send-otp- Send OTP for verificationPOST /user-registration- Register new userPOST /login- User loginPOST /reset-password- Reset passwordGET /get-plans- Get available subscription plans
Protected Routes (Authentication Required)
GET /check-session- Verify sessionPOST /organization- Create organizationGET /org-member- Get organization membersPOST /invitation- Send invitationGET /get-countries- Get countries listPOST /payment-gateway- Payment gateway integrationGET /purchased-plans- Get purchased plans
Environment Variables
While the library doesn't use .env files directly, you may want to use them in your application:
PORT=3000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your-password
DB_NAME=your-database
JWT_SECRET=your-jwt-secret
CLIENT_URL=http://localhost:3000TypeScript Support
The library is written in TypeScript and includes type definitions. Import types as needed:
import { SideKickConfig, AppInfo, CorsConfig, JwtConfig, CustomRoutesHandler, DatabaseConnection } from 'sidekick-server';Development
If you want to contribute or modify the library:
# Clone the repository
git clone <repository-url>
# Install dependencies
npm install
# Install peer dependencies for development
npm install express cors mysql2
# Build the library
npm run build
# Run in development mode
npm run devLocal Testing with Yalc
For local testing before publishing to npm, use yalc:
# Install yalc globally (if not already installed)
npm install -g yalc
# In the library directory
npm run build:yalc
# or
yalc publish
# In your test project
yalc add sidekick-server
npm install
# After making changes to the library
npm run build:yalc # Automatically builds and pushes to yalc
# To remove from test project
yalc remove sidekick-server
npm installLicense
ISC
Author
Trinesh Lokhande
