npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@salimtahayacine/database-seeder

v1.0.0

Published

A secure Express middleware for database seeding with production protection

Readme

🌱 Database Seeder

npm version License: MIT

Un middleware Express sécurisé pour gérer le seeding de base de données avec protection automatique en production.

🚀 Fonctionnalités

  • Sécurité intégrée : Bloque automatiquement les requêtes en production
  • Simple d'utilisation : Une seule fonction à configurer
  • 📊 Monitoring : Logs détaillés et temps d'exécution
  • 🔧 Flexible : Compatible avec Mongoose, Sequelize, Prisma, SQL brut, etc.
  • 📦 TypeScript : Définitions de types incluses

📦 Installation

npm install @salim-yassine/database-seeder

🎯 Utilisation

Exemple avec Mongoose

const express = require('express');
const databaseSeeder = require('@salim-yassine/database-seeder');
const User = require('./models/User');

const app = express();

// Définir votre logique de seeding
const seedDatabase = async () => {
  await User.deleteMany({}); // Nettoyer la collection
  
  const users = await User.insertMany([
    { name: 'Admin', email: '[email protected]', role: 'admin' },
    { name: 'User', email: '[email protected]', role: 'user' }
  ]);
  
  return { inserted: users.length };
};

// Monter le routeur (accessible uniquement en développement)
app.use('/api/seed', databaseSeeder(seedDatabase));

app.listen(3000);

Exemple avec Sequelize

const seedDatabase = async () => {
  await User.destroy({ where: {}, truncate: true });
  
  const users = await User.bulkCreate([
    { name: 'Admin', email: '[email protected]' },
    { name: 'User', email: '[email protected]' }
  ]);
  
  return { count: users.length };
};

app.use('/api/seed', databaseSeeder(seedDatabase));

Exemple avec Prisma

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

const seedDatabase = async () => {
  await prisma.user.deleteMany();
  
  const users = await prisma.user.createMany({
    data: [
      { name: 'Admin', email: '[email protected]' },
      { name: 'User', email: '[email protected]' }
    ]
  });
  
  return users;
};

app.use('/api/seed', databaseSeeder(seedDatabase));

🔒 Sécurité

Le module bloque automatiquement toute tentative de seeding si NODE_ENV=production.

// En production, cette requête retournera une erreur 403
POST /api/seed
// Response: 403 Forbidden
{
  "success": false,
  "error": "DANGER: Database seeding is strictly disabled in production environment."
}

📡 API

Endpoint POST

Une fois monté, le routeur expose un endpoint POST :

# Exécuter le seeding
curl -X POST http://localhost:3000/api/seed

Réponse en cas de succès

{
  "success": true,
  "message": "Database seeded successfully.",
  "duration": "1234ms",
  "data": {
    "inserted": 2
  }
}

Réponse en cas d'erreur

{
  "success": false,
  "message": "An error occurred during database seeding.",
  "error": "Connection refused"
}

🛠️ Configuration TypeScript

import express from 'express';
import databaseSeeder from '@salim-yassine/database-seeder';

const app = express();

const seedDatabase = async (): Promise<{ count: number }> => {
  // Votre logique ici
  return { count: 10 };
};

app.use('/api/seed', databaseSeeder(seedDatabase));

⚙️ Variables d'environnement

# Développement (seeding autorisé)
NODE_ENV=development

# Production (seeding bloqué)
NODE_ENV=production

🧪 Tests

# En développement
npm run dev
# Puis : curl -X POST http://localhost:3000/api/seed

# Vérifier le blocage en production
NODE_ENV=production npm start
# Puis : curl -X POST http://localhost:3000/api/seed
# Devrait retourner 403 Forbidden

📝 Bonnes pratiques

  1. Toujours utiliser en développement uniquement
  2. Ne jamais exposer ce endpoint en production
  3. Utiliser des variables d'environnement pour les données sensibles
  4. Nettoyer les données existantes avant le seeding

🤝 Contribution

Les contributions sont les bienvenues ! N'hésitez pas à :

  1. Fork le projet
  2. Créer une branche (git checkout -b feature/AmazingFeature)
  3. Commit vos changements (git commit -m 'Add some AmazingFeature')
  4. Push vers la branche (git push origin feature/AmazingFeature)
  5. Ouvrir une Pull Request

📄 Licence

MIT © Salim Taha Yassine

🐛 Bugs & Support

Pour signaler un bug ou demander de l'aide :

👨‍💻 Auteur

Salim Taha Yassine

  • Full Stack Developer (Java Spring Boot / Angular / Ionic)
  • Passionné par DevOps, DevSecOps et Cybersécurité
  • GitHub: @salimtahayacine