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

@ovyn/api-server

v1.1.1

Published

Serveur REST type json-server + auth sans dépendances externes

Readme

@ovyn/api-server

Un serveur REST léger type json-server avec authentification JWT, support WebSockets et rechargement à chaud, le tout sans dépendances externes.

Installation

# Installation globale
npm install -g @ovyn/api-server

# Utilisation directe via npx
npx @ovyn/api-server db.json

Utilisation CLI

api-server [options] [dbFile]

Options

  • -p, --port <number> : Port d'écoute (défaut : 3000)
  • -s, --secret <string> : Secret JWT pour l'authentification (défaut : change-me)
  • -r, --rules <path> : Chemin vers un fichier de règles JSON (facultatif)
  • -v, --version : Affiche la version
  • -h, --help : Affiche l'aide

Exemples

# Lancer avec un fichier spécifique et un secret
api-server db.json --port 3000 --secret monsecret

# Utiliser un fichier de règles pour sécuriser les accès
api-server --rules rules.json

Structure des données (db.json)

Le fichier de base de données est un objet JSON où chaque clé représente une collection (un tableau d'objets).

{
  "posts": [
    { "id": 1, "title": "Hello World", "userId": 1 },
    { "id": 2, "title": "Mon deuxième post", "userId": 1 }
  ],
  "comments": [
    { "id": 1, "body": "Super !", "postId": 1 }
  ]
}

Sécurisation et Règles (rules.json)

Vous pouvez définir des permissions par collection dans un fichier rules.json. Les niveaux de permission sont :

  • * : Public (ouvert à tous)
  • auth : Utilisateur connecté requis (via token JWT)
  • owner : Propriétaire de la ressource uniquement (vérifie le champ userId par défaut)

Exemple de rules.json :

{
  "posts": {
    "GET": "*",
    "POST": "auth",
    "PUT": "owner",
    "DELETE": "owner"
  },
  "users": {
    "GET": "owner",
    "PUT": "owner"
  }
}

Note : Les utilisateurs avec le rôle admin (défini dans le token ou la DB) ont accès à tout par défaut.

Fonctionnalités

Authentification JWT

Le serveur gère nativement le hashage des mots de passe et la génération de tokens.

  • POST /register : Inscription d'un utilisateur
  • POST /login : Connexion et récupération du token

Un utilisateur admin par défaut est créé au premier lancement si la collection users est vide : [email protected] / Test1234=.

Filtrage, Tri et Pagination

  • Filtrage : GET /posts?title=Hello
  • Recherche : GET /posts?q=searchterm
  • Tri : GET /posts?_sort=id&_order=desc
  • Pagination : GET /posts?_page=1&_limit=10

WebSockets

Le serveur supporte les WebSockets pour les notifications en temps réel.

Souscription : Envoyez un message JSON pour vous abonner à une collection :

{ "type": "subscribe", "channel": "posts" }

Notifications : Vous recevrez des messages lors des modifications :

{ "type": "create", "channel": "posts", "data": { "id": 3, "title": "New" } }

Rechargement à chaud (Hot-reload)

Les modifications apportées au fichier db.json ou au fichier de règles sont détectées et appliquées instantanément sans redémarrage.

Tests

Le projet utilise Jest pour sa suite de tests :

npm test

Licence

MIT