Skip to content

alfycore/veko.js

 
 

Repository files navigation

🚀 Veko.js

An ultra-modern and intelligent web framework for Node.js with Express and EJS, designed for rapid and efficient development with intelligent hot reload, beautiful logging, extensible plugin system, and revolutionary auto-updater.

🚀 Veko.js v1.2.0

An ultra-modern and intelligent web framework for Node.js with Express and EJS, designed for rapid and efficient development with intelligent hot reload, beautiful logging, extensible plugin system, advanced code verification, and the most advanced auto-updater in the Node.js ecosystem.

✨ Features

  • 🔥 Intelligent Hot Reload - Selective reloading of modified routes
  • 🎨 Beautiful Logging - Colorful logging system with icons and timestamps
  • Integrated WebSocket - Real-time communication for development
  • 📁 Auto-loading - Routes, views, and middleware auto-configured
  • 🛠️ Development Mode - Advanced file monitoring
  • 🌐 Smart Prefetching - Route caching and prefetching
  • 🔌 Plugin System - Extensible architecture with hooks and complete API
  • 🛣️ Dynamic Route Management - Create/delete routes on-the-fly
  • 🎨 Advanced Layout System - Powerful templating with sections and helpers
  • 📦 Auto Module Installation - Automatic dependency management
  • 🔬 Advanced Code Verification - Comprehensive code quality analysis
  • 📊 HTML Reports - Beautiful verification reports with interactive dashboard
  • 🔒 Security Auditing - Advanced security vulnerability detection
  • 🧮 Complexity Analysis - Cyclomatic complexity and performance metrics
  • 🔄 Revolutionary Auto-Updater - The most advanced auto-updater in Node.js ecosystem
  • 🛡️ Security-First Updates - Automatic critical security updates with rollback protection
  • 💾 Intelligent Backup System - Smart backups with one-click rollback
  • 🎯 Multi-Channel Updates - Support for stable, beta, and alpha channels
  • 🎨 Interactive CLI - Beautiful command-line interface with auto-completion

📋 Changelog

🎉 Version 1.2.0 (Latest) - December 2024

🆕 Revolutionary Auto-Updater System

  • 🔄 Advanced Auto-Updater

    • Automatic version checking with intelligent scheduling
    • Multi-channel support (stable, beta, alpha, custom registries)
    • Security-first approach with cryptographic validation
    • Interactive CLI with beautiful colored interface
    • Real-time notifications and progress indicators
    • Seamless integration with existing applications
  • 🔒 Security-First Architecture

    • SHA512 integrity verification for all packages
    • Automatic security updates with priority handling
    • Rollback protection against failed updates
    • Vulnerability scanning before installation
    • Secure communication protocols
    • Audit trail for all operations
  • 💾 Smart Backup & Rollback System

    • Automatic backup before every update
    • Configurable backup retention (1-10 backups)
    • Instant rollback in case of failure
    • Backup size optimization and integrity verification
    • Selective file backup with smart exclusions
    • Emergency rollback functionality
  • 🎨 Interactive CLI Experience

    • Beautiful colored interface with emojis and animations
    • Auto-completion for all commands
    • Interactive configuration wizard
    • Real-time progress bars and status indicators
    • Comprehensive help system with examples
    • Menu-driven navigation
  • 📊 Advanced Monitoring & Statistics

    • Update history tracking with detailed logs
    • Performance metrics and success rates
    • Rollback statistics and failure analysis
    • Update channel analytics
    • System health monitoring
    • Historical trend analysis

🔄 Auto-Updater Quick Start

# Installation globale recommandée
npm install -g veko

# Commandes disponibles
veko update              # Lancer le gestionnaire de mises à jour interactif
veko update check        # Vérifier les mises à jour
veko update config       # Configurer l'auto-updater
veko update fix          # Réparer l'auto-updater en cas de problème

# Alternative sans installation globale
npx veko update          # Utiliser veko update sans installation globale

🔄 Auto-Updater Simplifié

L'auto-updater de Veko a été simplifié pour plus de stabilité et d'efficacité. Il se concentre maintenant sur les commandes essentielles et évite les interfaces interactives qui pourraient interférer avec le fonctionnement de l'application.

# Vérifier les mises à jour
veko update check

# Installer une mise à jour
veko update update

# Afficher la configuration
veko update config

# Modifier un paramètre de configuration
veko update config autoUpdate true

# Afficher les statistiques
veko update stats

# Restaurer une version précédente
veko update rollback

# Réparer l'auto-updater
veko update fix

# Afficher l'aide et les commandes disponibles
veko update help

🔧 Auto-Updater Robuste

L'auto-updater a été conçu pour être stable et ne jamais interférer avec le fonctionnement de l'application principale. Il offre :

  • Installation non-bloquante - Aucun risque de ralentissement de votre application
  • Mises à jour automatisées - Programmez des vérifications régulières
  • Gestion des erreurs avancée - Restauration automatique en cas d'échec
  • Système de backup - Avant toute mise à jour
  • Configuration simple - Via la ligne de commande

🔧 Auto-Updater Integration

const { App } = require('veko');

const app = new App({
  // Auto-updater configuration optimisée
  autoUpdater: {
    enabled: true,              // Activer l'auto-updater
    checkOnStart: true,         // Vérifier au démarrage
    autoUpdate: false,          // Mode manuel (recommandé)
    updateChannel: 'stable',    // stable | beta | alpha
    securityUpdates: true,      // Auto-installer les mises à jour de sécurité
    backupCount: 5,            // Nombre de backups à conserver
    checkInterval: 3600000,    // Vérifier chaque heure (en millisecondes)
    rollbackOnFailure: true    // Restauration automatique en cas d'échec
  }
});

app.listen();

🌐 RESTful Auto-Updater API

Built-in API endpoints for remote management:

// Check for updates programmatically
const updateInfo = await app.checkForUpdates();
console.log(updateInfo); // { hasUpdate: true, currentVersion: '1.0.0', latestVersion: '2.0.0' }

// Perform update
if (updateInfo.hasUpdate) {
  const success = await app.performUpdate(updateInfo);
  console.log('Update successful:', success);
}

// Rollback if needed
await app.rollbackUpdate();

// Get auto-updater status
const status = app.getAutoUpdaterInfo();
console.log(status); // { active: true, currentVersion: '2.0.0', config: {...}, stats: {...} }

🛡️ RESTful Endpoints

# Check for updates via HTTP
GET http://localhost:3000/_veko/updates/check

# Trigger update via HTTP
POST http://localhost:3000/_veko/updates/perform

# Get statistics via HTTP
GET http://localhost:3000/_veko/updates/stats

# Perform rollback via HTTP
POST http://localhost:3000/_veko/updates/rollback

🎯 Update Channels

Stable Channel (Production)

npx veko-update config
# Select "Update Channel" -> "stable"
  • ✅ Production-ready releases
  • ✅ Thoroughly tested and stable
  • ✅ Backward compatibility guaranteed
  • ✅ Recommended for production environments

Beta Channel (Testing)

npx veko-update config
# Select "Update Channel" -> "beta"
  • ✅ Pre-release versions with new features
  • ✅ Stability testing phase
  • ⚠️ May contain minor issues
  • 🎯 Perfect for testing environments

Alpha Channel (Development)

npx veko-update config
# Select "Update Channel" -> "alpha"
  • ✅ Cutting-edge features and improvements
  • ✅ Immediate access to latest developments
  • ⚠️ Experimental features included
  • 🚧 Development and testing use only

📊 Statistics Dashboard

npx veko-update stats

Comprehensive statistics including:

  • 📈 Total updates performed
  • ✅ Success/failure rates
  • 🔄 Rollback history and frequency
  • 📢 Update channel distribution
  • ⚡ Performance metrics and timing
  • 🔒 Security update history
  • 📅 Last check/update timestamps

📜 Previous Versions

Version 1.1.0

  • Initial plugin system implementation
  • Basic layout system with EJS integration
  • Hot reload functionality with WebSocket
  • CLI commands (dev, setup, build, start)
  • Basic logging system with colors
  • Auto-loading for routes and middleware

✨ Features

  • 🔥 Intelligent Hot Reload - Selective reloading of modified routes
  • 🎨 Beautiful Logging - Colorful logging system with icons and timestamps
  • Integrated WebSocket - Real-time communication for development
  • 📁 Auto-loading - Routes, views, and middleware auto-configured
  • 🛠️ Development Mode - Advanced file monitoring
  • 🌐 Smart Prefetching - Route caching and prefetching
  • 🔌 Plugin System - Extensible architecture with hooks and complete API
  • 🛣️ Dynamic Route Management - Create/delete routes on-the-fly
  • 🎨 Advanced Layout System - Powerful templating with sections and helpers
  • 📦 Auto Module Installation - Automatic dependency management

🚀 Installation

Global Installation (CLI)

npm install -g veko

Project Installation

npm install veko

📦 Quick Start

1. Create a New Project

# Create a new project
veko setup my-app

# With options
veko setup --name my-blog --template blog --git

# Available templates: default, api, blog, admin

2. Basic Application

const { App } = require('veko');

const app = new App({
  port: 3000,
  viewsDir: 'views',
  staticDir: 'public',
  routesDir: 'routes',
  layouts: {
    enabled: true,
    defaultLayout: 'main'
  },
  plugins: {
    enabled: true,
    autoLoad: true,
    pluginsDir: 'plugins'
  }
});

app.loadRoutes() // Automatically load all routes
   .listen();

3. Ultra-Modern Development Mode

const { startDev } = require('veko');

// Simple dev startup
startDev({ port: 3000 });

Or directly with the App class:

const { App } = require('veko');

const app = new App({
  port: 3000,
  isDev: true, // Enable development mode
  wsPort: 3008, // WebSocket port for hot reload
  watchDirs: ['views', 'routes', 'public'], // Watched directories
  layouts: {
    enabled: true,
    defaultLayout: 'main'
  },
  plugins: {
    enabled: true,
    autoLoad: true,
    pluginsDir: 'plugins'
  }
});

app.loadRoutes().listen();

4. CLI Commands

# Start development server
veko dev

# Start with custom port
veko dev --port 8080

# Create new project
veko setup my-project

# Create API project
veko setup --template api --name my-api

# Create blog project
veko setup --template blog --name my-blog

# Create admin project
veko setup --template admin --name admin-panel

🎨 Advanced Layout System

Veko.js includes a powerful layout system that automatically wraps your views with layouts, providing sections, helpers, and dynamic content injection.

Layout Configuration

const app = new App({
  layouts: {
    enabled: true,              // Enable layout system
    layoutsDir: 'views/layouts', // Layout directory
    defaultLayout: 'main',       // Default layout name
    extension: '.ejs',           // Layout file extension
    sections: ['head', 'header', 'content', 'footer', 'scripts'],
    cache: true                  // Cache layouts in production
  }
});

Creating Layouts

views/layouts/main.ejs:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= meta.title || 'Veko.js App' %></title>
    
    <% if (meta.description) { %>
    <meta name="description" content="<%= meta.description %>">
    <% } %>
    
    <!-- Default CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Custom CSS -->
    <% if (layout && layout.css) { %>
        <% layout.css.forEach(href => { %>
        <link rel="stylesheet" href="<%= href %>">
        <% }); %>
    <% } %>
    
    <!-- Custom head section -->
    <% if (sections && sections.head) { %>
    <%- sections.head %>
    <% } %>
</head>
<body class="<%= layout && layout.bodyClass || '' %>">
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/">🚀 Veko.js</a>
            <div class="navbar-nav ms-auto">
                <a class="nav-link" href="/">Home</a>
                <a class="nav-link" href="/about">About</a>
                <a class="nav-link" href="/contact">Contact</a>
            </div>
        </div>
    </nav>
    
    <!-- Custom header -->
    <% if (sections && sections.header) { %>
    <header>
        <%- sections.header %>
    </header>
    <% } %>
    
    <!-- Main content -->
    <main class="container my-4">
        <%- sections.content %>
    </main>
    
    <!-- Footer -->
    <footer class="bg-dark text-light py-4 mt-5">
        <div class="container">
            <% if (sections && sections.footer) { %>
            <%- sections.footer %>
            <% } else { %>
            <p>&copy; <%= new Date().getFullYear() %> - Powered by Veko.js ⚡</p>
            <% } %>
        </div>
    </footer>
    
    <!-- JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- Custom JS -->
    <% if (layout && layout.js) { %>
        <% layout.js.forEach(src => { %>
        <script src="<%= src %>"></script>
        <% }); %>
    <% } %>
    
    <!-- Custom scripts section -->
    <% if (sections && sections.scripts) { %>
    <%- sections.scripts %>
    <% } %>
</body>
</html>

Using Layouts in Views

views/home.ejs:

<% layout.title('Home - My App') %>
<% layout.meta('description', 'Welcome to my Veko.js application') %>
<% layout.css('/css/home.css') %>

<% layout.section('header', `
<div class="jumbotron bg-gradient text-center text-white p-5">
    <h1>🎉 Welcome to Veko.js</h1>
    <p>Ultra-modern Node.js framework</p>
</div>
`) %>

<div class="row">
    <div class="col-md-4">
        <div class="card">
            <div class="card-body">
                <h3>🚀 Fast</h3>
                <p>Optimized performance and ultra-fast loading times.</p>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card">
            <div class="card-body">
                <h3>💎 Modern</h3>
                <p>Cutting-edge technologies and modern architecture.</p>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card">
            <div class="card-body">
                <h3>🎨 Flexible</h3>
                <p>Advanced layout system and reusable components.</p>
            </div>
        </div>
    </div>
</div>

<% layout.section('scripts', `
<script>
    console.log('✨ Page loaded with Veko.js!');
    
    // Card hover animations
    document.querySelectorAll('.card').forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-5px)';
            this.style.transition = 'transform 0.3s ease';
        });
        
        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0)';
        });
    });
</script>
`) %>

Layout Helpers

Available helpers in your views:

// Set page title
<% layout.title('My Page Title') %>

// Add meta tags
<% layout.meta('description', 'Page description') %>
<% layout.meta('keywords', 'veko, nodejs, framework') %>

// Add CSS files
<% layout.css('/css/custom.css') %>
<% layout.css('https://cdn.example.com/lib.css') %>

// Add JavaScript files
<% layout.js('/js/custom.js') %>
<% layout.js('https://cdn.example.com/lib.js') %>

// Define sections
<% layout.section('sectionName', 'content') %>
<% layout.section('header', `
<div class="custom-header">
    <h1>Custom Header</h1>
</div>
`) %>

Layout Management API

// Create a new layout
app.createLayout('admin', customLayoutContent);

// Delete a layout
app.deleteLayout('admin');

// List all available layouts
const layouts = app.listLayouts();

// Reload layouts in development mode
app.reloadLayouts();

// Render with specific layout
app.renderWithCustomLayout(res, 'view', 'admin', data);

// Render without layout
app.renderWithoutLayout(res, 'view', data);

🔌 Plugin System

Veko.js includes a powerful and extensible plugin system that allows adding functionality without modifying the framework core.

Plugin Configuration

const app = new App({
  plugins: {
    enabled: true,          // Enable plugin system
    autoLoad: true,         // Automatic plugin loading
    pluginsDir: 'plugins'   // Plugin directory
  }
});

Plugin Structure

// plugins/my-plugin.js
module.exports = {
  name: 'my-plugin',
  version: '1.0.0',
  description: 'Description of my plugin',
  author: 'My Name',
  
  // Dependencies (other required plugins)
  dependencies: ['other-plugin'],
  
  // Default configuration
  defaultConfig: {
    enabled: true,
    option1: 'value'
  },

  // Method called during loading
  async load(app, config, context) {
    // Your initialization code
    context.log('success', 'Plugin loaded!');
    
    // Add a route
    context.addRoute('get', '/my-plugin', (req, res) => {
      res.json({ message: 'Hello from plugin!' });
    });
    
    // Add middleware
    context.addMiddleware((req, res, next) => {
      req.pluginData = { source: 'my-plugin' };
      next();
    });
    
    // Add hooks
    context.hook('route:create', (method, path) => {
      context.log('info', `Route created: ${method} ${path}`);
    });
  },

  // Method called during unloading
  async unload(app, config) {
    console.log('Plugin unloaded');
  },

  // Activation/deactivation
  async activate(app, config) {
    console.log('Plugin activated');
  },

  async deactivate(app, config) {
    console.log('Plugin deactivated');
  }
};

Plugin Context API

Each plugin receives a rich context with numerous functionalities:

async load(app, config, context) {
  // === HOOKS ===
  // Add a hook
  context.hook('hookName', callback);
  context.removeHook('hookName', callback);
  
  // === ROUTES AND MIDDLEWARE ===
  // Add a route
  context.addRoute('get', '/path', handler);
  
  // Add middleware
  context.addMiddleware(middlewareFunction);
  
  // Add CLI command
  context.addCommand('name', handler, 'description');
  
  // === LOGGING ===
  // Log with automatic plugin name
  context.log('success', 'Message', 'details');
  
  // === ACCESS TO OTHER PLUGINS ===
  // Get another plugin
  const otherPlugin = context.getPlugin('other-plugin');
  
  // List all plugins
  const plugins = context.listPlugins();
  
  // === CONFIGURATION ===
  // Read config
  const config = context.getConfig();
  
  // Modify config
  context.updateConfig({ newOption: 'value' });
  
  // === PERSISTENT STORAGE ===
  // Save data
  context.storage.set('key', 'value');
  context.storage.set({ key1: 'value1', key2: 'value2' });
  
  // Read data
  const value = context.storage.get('key', 'defaultValue');
  const allData = context.storage.get();
  
  // Delete data
  context.storage.delete('key');
  context.storage.clear();
}

Plugin Management

// Load plugin manually
await app.loadPlugin('plugin-name', { option: 'value' });

// Unload plugin
await app.unloadPlugin('plugin-name');

// Reload plugin
await app.reloadPlugin('plugin-name', { newConfig: true });

// List plugins
const plugins = app.listPlugins();

// Enable/disable plugin
await app.plugins.togglePlugin('plugin-name', true);

// Statistics
const stats = app.plugins.getStats();
console.log(`${stats.active}/${stats.total} plugins active`);

Available Hooks

The plugin system provides numerous built-in hooks:

// Application hooks
app:init          // Application initialization
app:start         // Server startup
app:stop          // Server shutdown

// Route hooks
route:load        // Route loading
route:create      // Route creation
route:created     // Route created (after)
route:delete      // Route deletion

// Request hooks
request:start     // Request start
request:end       // Request end

// WebSocket hooks
websocket:connect    // WebSocket connection
websocket:disconnect // WebSocket disconnection

// File hooks
file:change       // File modification

// Plugin hooks
plugin:load       // Plugin loading
plugin:unload     // Plugin unloading

// Error hooks
error:handle      // Error handling

Plugin Examples

Database Plugin

// plugins/database.js
const mongoose = require('mongoose');

module.exports = {
  name: 'database',
  version: '1.0.0',
  description: 'MongoDB connection plugin',
  
  defaultConfig: {
    uri: 'mongodb://localhost:27017/myapp',
    options: {
      useNewUrlParser: true,
      useUnifiedTopology: true
    }
  },

  async load(app, config, context) {
    try {
      await mongoose.connect(config.uri, config.options);
      context.log('success', 'MongoDB connection established');
      
      // Expose mongoose in app
      app.db = mongoose;
      
      // Shutdown hook
      context.hook('app:stop', async () => {
        await mongoose.disconnect();
        context.log('info', 'MongoDB connection closed');
      });
      
    } catch (error) {
      context.log('error', 'MongoDB connection error', error.message);
      throw error;
    }
  },

  async unload() {
    await mongoose.disconnect();
  }
};

Authentication Plugin

// plugins/auth.js
const jwt = require('jsonwebtoken');

module.exports = {
  name: 'auth',
  version: '1.0.0',
  description: 'JWT authentication plugin',
  dependencies: ['database'],
  
  defaultConfig: {
    secret: 'your-secret-key',
    expiresIn: '24h'
  },

  async load(app, config, context) {
    // Authentication middleware
    const authMiddleware = (req, res, next) => {
      const token = req.headers.authorization?.split(' ')[1];
      
      if (!token) {
        return res.status(401).json({ error: 'Missing token' });
      }
      
      try {
        const decoded = jwt.verify(token, config.secret);
        req.user = decoded;
        next();
      } catch (error) {
        res.status(401).json({ error: 'Invalid token' });
      }
    };
    
    // Authentication routes
    context.addRoute('post', '/auth/login', async (req, res) => {
      const { email, password } = req.body;
      
      // User validation (example)
      const user = await validateUser(email, password);
      
      if (user) {
        const token = jwt.sign(
          { id: user.id, email: user.email },
          config.secret,
          { expiresIn: config.expiresIn }
        );
        
        res.json({ token, user });
      } else {
        res.status(401).json({ error: 'Invalid credentials' });
      }
    });
    
    context.addRoute('get', '/auth/profile', authMiddleware, (req, res) => {
      res.json({ user: req.user });
    });
    
    // Expose middleware in app
    app.authMiddleware = authMiddleware;
    
    context.log('success', 'Authentication plugin loaded');
  }
};

Cache Plugin

// plugins/cache.js
const NodeCache = require('node-cache');

module.exports = {
  name: 'cache',
  version: '1.0.0',
  description: 'In-memory cache plugin',
  
  defaultConfig: {
    stdTTL: 600, // 10 minutes
    checkperiod: 120
  },

  async load(app, config, context) {
    const cache = new NodeCache(config);
    
    // Cache middleware
    const cacheMiddleware = (duration = 300) => {
      return (req, res, next) => {
        const key = req.originalUrl;
        const cached = cache.get(key);
        
        if (cached) {
          context.log('info', 'Cache hit', key);
          return res.json(cached);
        }
        
        const originalSend = res.json;
        res.json = function(data) {
          cache.set(key, data, duration);
          context.log('info', 'Cache set', key);
          return originalSend.call(this, data);
        };
        
        next();
      };
    };
    
    // Cache API
    app.cache = {
      get: (key) => cache.get(key),
      set: (key, value, ttl) => cache.set(key, value, ttl),
      del: (key) => cache.del(key),
      flush: () => cache.flushAll(),
      middleware: cacheMiddleware,
      stats: () => cache.getStats()
    };
    
    // Stats route
    context.addRoute('get', '/cache/stats', (req, res) => {
      res.json(cache.getStats());
    });
    
    context.log('success', 'Cache plugin loaded');
  }
};

Inline Plugin Creation

// Create a simple plugin directly in code
const simplePlugin = app.plugins.createSimplePlugin(
  'logger-plugin',
  (app, config, context) => {
    // Hook to log all requests
    context.hook('request:start', (req) => {
      context.log('info', `${req.method} ${req.url}`);
    });
    
    // Debug route
    context.addRoute('get', '/debug/logs', (req, res) => {
      res.json({
        plugin: 'logger-plugin',
        requests: context.storage.get('requestCount', 0)
      });
    });
  },
  {
    version: '1.0.0',
    description: 'Request logging plugin'
  }
);

await app.loadPlugin(simplePlugin);

🛣️ Dynamic Route Management

Veko.js allows creating, modifying, and deleting routes dynamically during runtime.

Dynamic Route Creation

// Create route on-the-fly
app.createRoute('get', '/api/dynamic', (req, res) => {
  res.json({ message: 'Route created dynamically!' });
});

// With middleware
app.createRoute('post', '/api/secure', [
  authMiddleware,
  validationMiddleware,
  (req, res) => {
    res.json({ success: true });
  }
]);

// Update existing route
app.updateRoute('get', '/api/dynamic', (req, res) => {
  res.json({ message: 'Route updated!' });
});

// Delete route
app.deleteRoute('get', '/api/dynamic');

Creating Route Files

// Create physical route file
app.createRouteFile('/users/profile', {
  get: (req, res) => {
    res.render('profile', { user: req.user });
  },
  post: (req, res) => {
    // Profile update
    res.json({ updated: true });
  }
}, {
  description: 'User profile management',
  middleware: [authMiddleware]
});

// Delete route file
app.deleteRouteFile('/users/profile');

// List all routes
const routes = app.listRoutes();
console.log(routes);

🎨 Beautiful Logging

Veko.js offers a revolutionary logging system with:

  • 🕒 Formatted timestamps
  • 🎯 Colored badges with Unicode icons
  • 📊 Specialized log types
  • 🌈 Optimized ANSI colors

Available Log Types

app.log('success', 'Operation successful', '✅ Additional details');
app.log('error', 'Critical error', '❌ Error message');
app.log('warning', 'Warning', '⚠️ Warning message');
app.log('info', 'Information', 'ℹ️ General info');
app.log('server', 'Server', '🚀 Server startup');
app.log('route', 'Route', '🌐 New route');
app.log('dev', 'Development', '🛠️ Dev mode');
app.log('file', 'File', '📁 File modification');
app.log('reload', 'Reload', '🔄 Hot reload');
app.log('create', 'Creation', '➕ Element created');
app.log('delete', 'Deletion', '🗑️ Element deleted');
app.log('install', 'Installation', '📦 Module installed');

Console Output Example

[2:32:15 PM] ✨  Server started successfully 🌐 http://localhost:3000
[2:32:16 PM] 🛠️  Development mode active 🔥 Intelligent hot reload on port 3008
[2:32:16 PM] 🔌  Plugin database loaded database v1.0.0
[2:32:16 PM] 🔌  Plugin auth loaded auth v1.0.0
[2:32:17 PM] 💎  Plugin system 🔌 2/2 plugins active
[2:32:17 PM] 🌐  Route loaded index.js → /
[2:32:18 PM] ➕  Route created dynamically GET /api/users
[2:32:19 PM] 📁  File modified 📝 routes/users.js
[2:32:19 PM] 🔄  Route reloaded 🔄 routes/users.js

🔥 Intelligent Hot Reload

Selective Reload by File Type

  • Modified routes → Route-only reload
  • Modified views → Light template reload
  • Static files → Full browser reload
  • Modified plugins → Specific plugin reload
  • Modified layouts → Layout cache clear and reload

Hot Reload Configuration

const app = new App({
  isDev: true,
  wsPort: 3008, // WebSocket port
  watchDirs: ['views', 'routes', 'public', 'src', 'plugins'], // Watched directories
  prefetch: {
    enabled: true,
    maxConcurrent: 3,
    notifyUser: true,
    cacheRoutes: true,
    prefetchDelay: 1000
  }
});

Automatic Client Script

The hot reload script is automatically injected into your pages:

// Automatically injected before </body>
<script>
(function() {
  const ws = new WebSocket('ws://localhost:3008');
  
  ws.onopen = () => console.log('🔗 Veko.js connected');
  ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    
    switch(data.type) {
      case 'reload':
        console.log('🔄 Full reload...');
        setTimeout(() => window.location.reload(), 300);
        break;
        
      case 'route-reload':
        console.log('🔄 Route reloaded:', data.route);
        if (window.location.pathname === data.route) {
          setTimeout(() => window.location.reload(), 300);
        }
        break;
        
      case 'route-created':
        console.log('➕ Route created:', data.method, data.path);
        break;
        
      case 'route-deleted':
        console.log('🗑️ Route deleted:', data.method, data.path);
        break;
        
      case 'view-reload':
        console.log('🎨 View reloaded:', data.file);
        setTimeout(() => window.location.reload(), 300);
        break;
        
      case 'layout-reload':
        console.log('🎨 Layout reloaded:', data.file);
        setTimeout(() => window.location.reload(), 300);
        break;
        
      case 'plugin-reload':
        console.log('🔌 Plugin reloaded:', data.plugin);
        break;
    }
  };
})();
</script>

📁 Project Structure

my-project/
├── routes/
│   ├── index.js          # Route: /
│   ├── about.js          # Route: /about
│   ├── users/
│   │   ├── index.js      # Route: /users
│   │   └── [id].js       # Route: /users/:id
│   └── api/
│       └── products.js   # Route: /api/products
├── views/
│   ├── layouts/          # Layout templates
│   │   ├── main.ejs      # Main layout
│   │   └── admin.ejs     # Admin layout
│   ├── partials/         # Reusable components
│   ├── index.ejs
│   └── about.ejs
├── public/
│   ├── css/
│   ├── js/
│   └── images/
├── plugins/              # Custom plugins
│   ├── database.js
│   ├── auth.js
│   └── cache.js
├── data/                 # Plugin data
│   └── plugins/
│       ├── database.json
│       └── auth.json
├── config/               # Configuration files
│   └── app.js
├── middleware/           # Custom middleware
└── package.json

🛣️ Route System

Automatic Routes

Veko.js automatically loads all routes from the routes/ folder. The filename determines the URL:

  • routes/index.js/
  • routes/about.js/about
  • routes/users/profile.js/users/profile
  • routes/api/users.js/api/users

Dynamic Parameters

Use brackets for parameters:

  • routes/users/[id].js/users/:id
  • routes/posts/[slug]/comments.js/posts/:slug/comments

Route File Formats

HTTP Methods (Recommended)

// routes/users.js
module.exports = {
  // GET /users
  get: (req, res) => {
    res.render('users', { users: [] });
  },
  
  // POST /users
  post: (req, res) => {
    const newUser = req.body;
    res.status(201).json({ user: newUser });
  },
  
  // PUT /users
  put: (req, res) => {
    res.json({ message: 'User updated' });
  },
  
  // DELETE /users
  delete: (req, res) => {
    res.json({ message: 'User deleted' });
  }
};

Custom Function

// routes/custom.js
module.exports = (app) => {
  app.get('/custom', (req, res) => {
    res.json({ message: 'Custom route' });
  });
  
  app.post('/custom/:action', middleware, (req, res) => {
    res.json({ action: req.params.action });
  });
};

⚡ Ultra-Modern Development Mode

Development mode includes:

  • 🔥 Intelligent Hot Reload - Selective reload by file type
  • 📡 WebSocket - Real-time server ↔ client communication
  • 🎨 Colorful Logs - Logging system with badges and icons
  • 🔍 Advanced Monitoring - File monitoring with chokidar
  • Performance - Reload only modified parts
  • 🛠️ Debugging - Detailed error messages with stack traces
  • 🔌 Hot Plugin Reload - Real-time plugin reloading

Complete Configuration

const app = new App({
  port: 3000,
  wsPort: 3008,
  viewsDir: 'views',
  staticDir: 'public',
  routesDir: 'routes',
  isDev: true,
  watchDirs: ['views', 'routes', 'public', 'src', 'plugins'],
  errorLog: 'error.log',
  showStack: true,
  autoInstall: true,
  layouts: {
    enabled: true,
    defaultLayout: 'main',
    layoutsDir: 'views/layouts',
    cache: false // Disable cache in dev mode
  },
  plugins: {
    enabled: true,
    autoLoad: true,
    pluginsDir: 'plugins'
  },
  prefetch: {
    enabled: true,
    maxConcurrent: 3,
    notifyUser: true,
    cacheRoutes: true,
    prefetchDelay: 1000
  }
});

Advanced Error Handling

// Automatic handling of uncaught errors
process.on('uncaughtException', (error) => {
  app.log('error', 'Uncaught exception', error.message);
  // Automatic WebSocket notification to clients
});

process.on('unhandledRejection', (reason) => {
  app.log('error', 'Promise rejected', reason.toString());
  // Automatic error broadcast
});

🎨 Views with EJS

Veko.js uses EJS as the default template engine with advanced configuration.

View Configuration

// Automatic view directory configuration
this.express.set('view engine', 'ejs');
this.express.set('views', [
  path.join(process.cwd(), this.options.viewsDir), // Project directory
  path.join(process.cwd(), this.options.layouts.layoutsDir), // Layouts directory
  path.join(__dirname, '..', 'views'),             // Veko.js views
  path.join(__dirname, '..', 'error')              // Error pages
]);

Modern View Example

<!-- views/index.ejs -->
<!DOCTYPE html>
<html>
<head>
  <title><%= title %></title>
  <link rel="stylesheet" href="/css/style.css">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
  <header>
    <h1><%= message %></h1>
  </header>
  
  <main>
    <% if (users && users.length > 0) { %>
      <section class="users">
        <% users.forEach(user => { %>
          <article class="user-card">
            <h3><%= user.name %></h3>
            <p><%= user.email %></p>
          </article>
        <% }); %>
      </section>
    <% } else { %>
      <p>No users found.</p>
    <% } %>
  </main>
  
  <!-- Hot reload script automatically injected in dev mode -->
</body>
</html>

📦 Auto Module Installation

Veko.js automatically installs missing dependencies during initialization.

Module Installation Configuration

const app = new App({
  autoInstall: true // Enable automatic installation (default: true)
});

// Check if module is available
if (app.isModuleAvailable('express')) {
  console.log('Express is available');
}

// Install module on-the-fly
await app.installModule('lodash', '4.17.21');

// Require module with auto-installation
const lodash = await app.requireModule('lodash');

Required Modules

Veko.js automatically manages these dependencies:

const requiredModules = {
  'express': '^4.18.2',
  'ejs': '^3.1.9',
  'ws': '^8.14.2',
  'chokidar': '^3.5.3',
  'chalk': '^4.1.2',
  'commander': '^11.1.0'
};

🔧 Complete API

App Class

Constructor

const app = new App({
  port: 3000,                    // Listening port
  wsPort: 3008,                  // WebSocket port (dev mode)
  viewsDir: 'views',             // Views directory
  staticDir: 'public',           // Static directory
  routesDir: 'routes',           // Routes directory
  isDev: false,                  // Development mode
  watchDirs: ['views', 'routes', 'public'], // Watched directories
  errorLog: 'error.log',         // Error log file
  showStack: true,               // Show stack trace
  autoInstall: true,             // Auto module installation
  layouts: {                     // Layout configuration
    enabled: true,
    defaultLayout: 'main',
    layoutsDir: 'views/layouts',
    extension: '.ejs',
    cache: true
  },
  plugins: {                     // Plugin configuration
    enabled: true,
    autoLoad: true,
    pluginsDir: 'plugins'
  },
  prefetch: {                    // Prefetch configuration
    enabled: true,
    maxConcurrent: 3,
    notifyUser: true,
    cacheRoutes: true,
    prefetchDelay: 1000
  }
});

Main Methods

// Loading and startup
app.loadRoutes(routesDir)        // Load routes automatically
app.listen(port)                 // Start server
app.startDev(port)              // Start in development mode
app.stop()                      // Stop server

// Middleware and configuration
app.use(middleware)             // Add middleware
app.setupExpress()              // Configure Express
app.setupDevMode()              // Enable development mode

// Beautiful logging
app.log(type, message, details) // Advanced logging system

// Dynamic route management
app.createRoute(method, path, handler, options)  // Create route dynamically
app.deleteRoute(method, path)                    // Delete route
app.updateRoute(method, path, newHandler)        // Update route
app.createRouteFile(routePath, handlers, options) // Create route file
app.deleteRouteFile(routePath)                   // Delete route file
app.listRoutes()                                 // List all routes

// Layout management
app.createLayout(name, content)                  // Create layout
app.deleteLayout(name)                           // Delete layout
app.listLayouts()                                // List layouts
app.reloadLayouts()                              // Reload layouts
app.renderWithCustomLayout(res, view, layout, data) // Render with specific layout
app.renderWithoutLayout(res, view, data)         // Render without layout

// Module management
app.installModule(name, version)                 // Install module
app.isModuleAvailable(name)                      // Check module availability
app.requireModule(name, version)                 // Require with auto-install

// Route management (internal)
app.reloadSpecificRoute(filePath)   // Reload specific route
app.removeRoute(filePath)           // Remove route
app.filePathToRoute(filePath)       // Convert path → route

// WebSocket and broadcast
app.broadcast(data)                 // Broadcast WebSocket message
app.sendAvailableRoutes(ws)         // Send available routes

// Plugin management
app.loadPlugin(plugin, config)      // Load plugin
app.unloadPlugin(pluginName)        // Unload plugin
app.reloadPlugin(pluginName, config) // Reload plugin
app.listPlugins()                   // List plugins
app.executeHook(hookName, ...args)  // Execute hook

Utility Functions

const { createApp, startDev, start } = require('veko');

// Quick app creation
const app = createApp({ port: 3000 });

// Development startup
startDev({ port: 3000, watchDirs: ['src'] });

// Production startup
start({ port: 8080 });

🔍 Advanced Examples

Complete Application with Plugins

const { App } = require('veko');

const app = new App({
  port: 3000,
  isDev: process.env.NODE_ENV === 'development',
  layouts: {
    enabled: true,
    defaultLayout: 'main'
  },
  plugins: {
    enabled: true,
    autoLoad: true,
    pluginsDir: 'plugins'
  }
});

// Load plugins with specific configuration
await app.loadPlugin('database', {
  uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/myapp'
});

await app.loadPlugin('auth', {
  secret: process.env.JWT_SECRET || 'development-secret',
  expiresIn: '7d'
});

await app.loadPlugin('cache', {
  stdTTL: 3600 // 1 hour
});

// Add global hooks
app.plugins.addHook('request:start', (req) => {
  app.log('info', `${req.method} ${req.url}`, `IP: ${req.ip}`);
});

app.plugins.addHook('error:handle', (error, req) => {
  app.log('error', 'Application error', `${error.message} - ${req.url}`);
});

app.loadRoutes().listen();

Modern REST API with Error Handling

// routes/api/users.js
const users = [];

module.exports = {
  get: async (req, res) => {
    try {
      // Use plugin cache
      const cacheKey = `users:${JSON.stringify(req.query)}`;
      const cached = req.app.cache?.get(cacheKey);
      
      if (cached) {
        return res.json(cached);
      }
      
      // Database simulation
      const page = parseInt(req.query.page) || 1;
      const limit = parseInt(req.query.limit) || 10;
      const start = (page - 1) * limit;
      const end = start + limit;
      
      const paginatedUsers = users.slice(start, end);
      
      const result = {
        users: paginatedUsers,
        pagination: {
          page,
          limit,
          total: users.length,
          pages: Math.ceil(users.length / limit)
        }
      };
      
      // Cache result
      req.app.cache?.set(cacheKey, result, 300);
      
      res.json(result);
    } catch (error) {
      res.status(500).json({ error: 'Server error' });
    }
  },
  
  post: [
    // Use auth middleware from plugin
    (req, res, next) => req.app.authMiddleware?.(req, res, next) || next(),
    
    async (req, res) => {
      try {
        const { name, email } = req.body;
        
        if (!name || !email) {
          return res.status(400).json({ 
            error: 'Name and email required' 
          });
        }
        
        const newUser = {
          id: users.length + 1,
          name,
          email,
          createdAt: new Date().toISOString()
        };
        
        users.push(newUser);
        
        // Invalidate cache
        req.app.cache?.del('users:*');
        
        res.status(201).json({ 
          message: 'User created',
          user: newUser 
        });
      } catch (error) {
        res.status(500).json({ error: 'Server error' });
      }
    }
  ]
};

Advanced Plugin with CLI

// plugins/admin.js
module.exports = {
  name: 'admin',
  version: '2.0.0',
  description: 'Advanced administration plugin',
  dependencies: ['database', 'auth'],
  
  defaultConfig: {
    adminPath: '/admin',
    secretKey: 'admin-secret'
  },

  async load(app, config, context) {
    // Admin-only middleware
    const adminMiddleware = (req, res, next) => {
      if (!req.user || req.user.role !== 'admin') {
        return res.status(403).json({ error: 'Access denied' });
      }
      next();
    };

    // Administration routes
    context.addRoute('get', `${config.adminPath}/dashboard`, [
      app.authMiddleware,
      adminMiddleware,
      (req, res) => {
        res.render('admin/dashboard', {
          layout: 'admin',
          stats: context.storage.get('stats', {}),
          plugins: context.listPlugins()
        });
      }
    ]);

    // Plugin management API
    context.addRoute('post', `${config.adminPath}/plugins/:name/toggle`, [
      app.authMiddleware,
      adminMiddleware,
      async (req, res) => {
        try {
          const { name } = req.params;
          const result = await context.getPlugin('plugins')?.togglePlugin(name);
          res.json({ success: true, active: result });
        } catch (error) {
          res.status(500).json({ error: error.message });
        }
      }
    ]);

    // CLI commands
    context.addCommand('admin:stats', () => {
      console.log('=== Admin Statistics ===');
      console.log('Plugins:', context.listPlugins().length);
      console.log('Stats:', context.storage.get('stats', {}));
    }, 'Display administration statistics');

    context.addCommand('admin:reset', () => {
      context.storage.clear();
      console.log('Admin data reset');
    }, 'Reset administration data');

    // Hook to collect stats
    context.hook('request:end', (req, res) => {
      const stats = context.storage.get('stats', { requests: 0, errors: 0 });
      stats.requests++;
      
      if (res.statusCode >= 400) {
        stats.errors++;
      }
      
      context.storage.set('stats', stats);
    });

    context.log('success', 'Admin plugin loaded', `Interface: ${config.adminPath}`);
  }
};

🚀 Deployment

Production Mode

// app.js
const { App } = require('veko');

const app = new App({
  port: process.env.PORT || 3000,
  isDev: false, // Disable development mode
  errorLog: 'logs/error.log',
  showStack: false, // Hide stack traces in production
  autoInstall: false, // Disable auto-installation in production
  layouts: {
    enabled: true,
    cache: true // Enable layout caching
  },
  plugins: {
    enabled: true,
    autoLoad: true,
    pluginsDir: 'plugins'
  }
});

app.loadRoutes().listen();

Environment Variables

# .env
NODE_ENV=production
PORT=8080
LOG_LEVEL=info
MONGODB_URI=mongodb://prod-server:27017/myapp
JWT_SECRET=super-secret-production-key

Docker

FROM node:18-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

EXPOSE 3000

CMD ["node", "app.js"]

📊 Performance and Optimization

Smart Prefetching

const app = new App({
  prefetch: {
    enabled: true,          // Enable prefetching
    maxConcurrent: 3,       // Max simultaneous requests
    notifyUser: true,       // Notify user
    cacheRoutes: true,      // Route caching
    prefetchDelay: 1000     // Delay before prefetching
  }
});

Performance Monitoring

// Monitoring plugin
const monitoringPlugin = {
  name: 'monitoring',
  
  async load(app, config, context) {
    context.hook('request:start', (req) => {
      req.startTime = process.hrtime.bigint();
    });
    
    context.hook('request:end', (req, res) => {
      const duration = Number(process.hrtime.bigint() - req.startTime) / 1000000;
      
      if (duration > 100) {
        context.log('warning', 'Slow request detected', 
          `${req.method} ${req.url} - ${duration.toFixed(2)}ms`);
      }
      
      // Store metrics
      const metrics = context.storage.get('metrics', { slow: 0, total: 0 });
      metrics.total++;
      if (duration > 100) metrics.slow++;
      context.storage.set('metrics', metrics);
    });
  }
};

app.loadPlugin(monitoringPlugin);

🛠️ CLI Commands

Setup Commands

# Create new project with default template
veko setup my-app

# Create with specific template
veko setup --template api --name my-api
veko setup --template blog --name my-blog  
veko setup --template admin --name admin-panel

# Setup with options
veko setup my-app --git --skip-install
veko setup --name my-app --dir ./projects/my-app

Development Commands

# Start development server
veko dev

# Start with custom port
veko dev --port 8080

# Start with custom watch directories
veko dev --watch "src,views,routes"

# Start with custom entry file
veko dev --file ./src/server.js

Build Commands

# Build for production
veko build

# Start production server
veko start

🤝 Contributing

Contributions are welcome!

Local Development

git clone https://github.com/username/veko.js.git
cd veko.js
npm install
npm run dev

Testing

npm test
npm run test:watch
npm run test:coverage

Creating a Plugin

  1. Create a file in plugins/
  2. Follow the documented plugin structure
  3. Test in development mode
  4. Submit a PR

Code Style

  • Use ES6+ features
  • Follow JSDoc comments
  • Use meaningful variable names
  • Add unit tests for new features

📄 License

MIT License - see LICENSE file for details.


Veko.js v2.0 - Ultra-modern web framework with the most advanced auto-updater in the Node.js ecosystem 🚀🔄

Quick Auto-Updater Commands

veko update              # 🎨 Menu interactif
veko update check        # 🔍 Vérification des mises à jour  
veko update update       # ⚡ Mettre à jour maintenant
veko update status       # 📊 Afficher le statut
veko update daemon       # 👾 Mode arrière-plan
veko update --help       # ❓ Aide complète

Quick Links

Built with ❤️ by the Veko.js team

Experience the future of Node.js development with Veko.js 2.0! 🚀✨

About

Fast, unopinionated, minimalist web framework for node.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 74.8%
  • JavaScript 23.3%
  • EJS 1.5%
  • Other 0.4%