Skip to content

jodit/jodit-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

73 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jodit Connector Application (Node.js)

CI/CD Documentation npm version License: MIT

Node.js/TypeScript implementation of the Jodit File Browser and Uploader connector.

Links:

Technology Stack

  • Node.js LTS (v18+)
  • TypeScript with strict typing
  • Express 5.x for REST API
  • Zod for runtime validation
  • @hapi/boom for error handling
  • Winston for logging
  • Jest + Supertest for testing

Installation

npm install jodit-nodejs

Quick Start

Basic Usage (TypeScript)

import { start } from 'jodit-nodejs';

// Start server with default config
const server = await start(8081);
console.log('Server running on http://localhost:8081');

Basic Usage (JavaScript)

const { start } = require('jodit-nodejs');

async function main() {
  const server = await start(8081);
  console.log('Server running on http://localhost:8081');
}

main().catch(console.error);

With Custom Configuration

import { start } from 'jodit-nodejs';

await start({
  port: 8081,
  config: {
    debug: false,
    allowCrossOrigin: true,
    sources: {
      uploads: {
        name: 'uploads',
        title: 'User Uploads',
        root: '/var/www/uploads',
        // NGINX or CDN base URL for accessing files
        baseurl: 'http://localhost:8080/uploads/'
      }
    }
  }
});

With Authentication

import { start, type AuthCallback } from 'jodit-nodejs';

const checkAuth: AuthCallback = async (req) => {
  const token = req.headers.authorization;
  if (!token) return 'guest';

  const user = await validateToken(token);
  return user.role; // 'admin', 'editor', 'guest', etc.
};

await start({
  port: 8081,
  config: {
    defaultRole: 'guest',
    accessControl: [
      { role: 'guest', FILES: true, FILE_UPLOAD: false },
      { role: 'admin', FILES: true, FILE_UPLOAD: true }
    ]
  },
  checkAuthentication: checkAuth
});

Security: POST-only Mode

For enhanced security, you can restrict the API to only accept POST requests:

import { start } from 'jodit-nodejs';

await start({
  port: 8081,
  config: {
    onlyPOST: true,  // Block all GET requests
    sources: {
      uploads: {
        name: 'uploads',
        title: 'User Uploads',
        root: '/var/www/uploads',
        baseurl: 'http://localhost:8080/uploads/'
      }
    }
  }
});

When onlyPOST is enabled:

  • All GET requests return 405 Method Not Allowed
  • Provides protection against CSRF attacks
  • Prevents parameter leakage in server logs

Documentation

πŸ“– Complete Documentation - Full documentation with guides and API reference

Quick Links:

OpenAPI Specification:

Key Features

  • βœ… Full file management - browse, upload, rename, move, delete
  • βœ… Folder operations - create, rename, move, delete, tree view
  • βœ… Image processing - resize, crop, thumbnail generation
  • βœ… Document generation - PDF and DOCX from HTML
  • βœ… Access control - role-based permissions, path restrictions
  • βœ… Authentication - cookie, JWT, express-session support
  • βœ… Security - POST-only mode, CSRF protection
  • βœ… Express integration - standalone or integrate with existing apps
  • βœ… Custom storage - local filesystem, S3, Azure, Google Cloud, etc.
  • βœ… TypeScript - full type safety with strict typing
  • βœ… Validation - Zod schemas for runtime validation
  • βœ… Testing - comprehensive test suite with Jest + Supertest
  • βœ… Docker - multi-stage build for production deployment

Implemented Functions

  • βœ… actionFiles - get list of files
  • βœ… actionFileUpload - upload files
  • βœ… actionFileUploadRemote - upload file from remote URL
  • βœ… actionFileRemove - remove files
  • βœ… actionFileMove - move files
  • βœ… actionFileRename - rename files
  • βœ… actionFileDownload - download file
  • βœ… actionGetLocalFileByUrl - resolve local file by URL
  • βœ… actionFolderCreate - create folders
  • βœ… actionFolderRemove - remove folders
  • βœ… actionFolderMove - move folders
  • βœ… actionFolderRename - rename folders
  • βœ… actionFolders - get folder tree
  • βœ… actionPermissions - get permissions
  • βœ… actionImageResize - resize images
  • βœ… actionImageCrop - crop images
  • βœ… actionGenerateDocx - generate DOCX documents from HTML
  • βœ… actionGeneratePdf - generate PDF documents from HTML

Examples

Check the examples/ directory for complete working examples:

  • examples/basic-js.js - Simple server setup
  • examples/with-auth-js.js - With authentication callback
  • examples/with-cookie-auth.js - Cookie-based authentication
  • examples/with-jwt-auth.js - JWT token authentication
  • examples/with-express-session.js - Express-session integration

Scripts

npm run dev          # Development with hot reload
npm run build        # Compile TypeScript
npm start            # Run compiled application
npm test             # Run tests
npm run lint         # Check code quality

Docker

# Build and run
docker build -t jodit-nodejs .
docker run --rm -p 8081:8081 jodit-nodejs

# With custom config
docker run --rm -p 8081:8081 \
  -v /host/path/to/config.json:/usr/src/app/config.json \
  -v /host/path/to/files:/usr/src/app/files \
  jodit-nodejs

License

MIT

About

Jodit FileBrowser and Uploader connector for Node.js

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages