| name | develop-b24-node |
| description | Develop backend applications for Bitrix24 using Node.js, Express, and Bitrix24 JS SDK. Use this skill when you need to create API endpoints, work with Bitrix24 data, or manage authentication in Node.js. |
Develop Bitrix24 Node.js Backend
Quick Start
The Node.js backend is built with Express and uses @bitrix24/b24jssdk for Bitrix24 interaction.
Key Files
backends/node/api/server.js: Main entry point and API routes.
backends/node/api/utils/verifyToken.js: JWT verification middleware.
Creating API Endpoints
Use Express routing and the verifyToken middleware.
import verifyToken from './utils/verifyToken.js';
app.get('/api/my-endpoint', verifyToken, async (req, res) => {
res.json({ data: 'value' });
});
Bitrix24 Interaction (JS SDK)
Use @bitrix24/b24jssdk (specifically B24Hook for backend or B24Frame if rendering UI, but usually backend uses Hook or OAuth).
Initialization
import { B24Hook } from '@bitrix24/b24jssdk';
const b24 = new B24Hook({
b24Url: 'https://your-portal.bitrix24.com',
userId: 1,
secret: 'webhook_token'
});
Common Operations
const result = await b24.callMethod('crm.deal.list', {
select: ['ID', 'TITLE']
});
const deals = result.getData();
Authentication Flow
- Installation:
/api/install receives OAuth data.
- Token Issue:
/api/getToken issues a JWT for the frontend using jsonwebtoken.
- Requests: Frontend sends JWT in
Authorization header. verifyToken middleware validates it.
Database
- Drivers:
pg (PostgreSQL) or mysql2 (MySQL).
- Configuration: Based on
DB_TYPE env var.
- Connection:
pool object in server.js.
Best Practices
- Middleware: Use
verifyToken for protected routes.
- Async/Await: Use async/await for database and API calls.
- Environment: Use
process.env for configuration.