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 🙏

© 2025 – Pkg Stats / Ryan Hefner

authjson

v1.0.1

Published

Un servidor RESTful con autenticación JWT, inspirado en json-server.

Readme

AuthJSON

AuthJSON es un servidor RESTful inspirado en json-server, pero con una capa de autenticación basada en JWT (JSON Web Tokens). Permite crear una API RESTful a partir de un archivo db.json, con operaciones CRUD y autenticación integrada.

Características

  • Autenticación JWT: Registro e inicio de sesión con generación de tokens JWT.
  • Operaciones CRUD: Crear, leer, actualizar y eliminar recursos de manera dinámica.
  • Monitoreo de cambios: Detecta cambios en el archivo db.json en tiempo real.
  • Fácil de usar: Configuración mínima y compatible con json-server.

Instalación

Puedes instalar AuthJSON globalmente usando npm:

npm install -g authjson

O como dependencia en tu proyecto:

npm install authjson

Uso

1. Crear un archivo db.json

Crea una carpeta data en la raíz de tu protecto y un archivo db.json con la estructura de datos que desees. Por ejemplo:

{
  "users": [
    { "id": 1, "userId": "123", "name": "Daniel", "email": "[email protected]" }
  ],
  "posts": [
    { "id": 1, "userId": "123", "title": "Mi primer post", "content": "Hola mundo" }
  ]
}

2. Configuración

Variables de entorno

DB_PATH: Ruta al archivo db.json.

PORT: Puerto en el que se ejecutará el servidor (por defecto: 3001).

SECRET_JWT_SEED: Clave secreta para la generación de tokens JWT. Si no se configura, se usará una clave predeterminada ('default-secret-key').

Argumentos de línea de comandos

--db <ruta>: Especifica la ruta al archivo db.json.

3. Iniciar el servidor

Puedes iniciar el servidor especificando la ruta de db.json como argumento de línea de comandos:

authjson --db ./ruta/al/db.json

O configurando la variable de entorno DB_PATH:

DB_PATH=./ruta/al/db.json

El servidor se iniciará en el puerto 3001 (o el que especifiques en la variable de entorno PORT).

4. Endpoints disponibles

Al iniciar el servidor, se mostrarán en la consola los endpoints disponibles. Por ejemplo:

🔗 **AuthJSON Endpoints:**
📌 Base URL: http://localhost:3001/

🔑 **Autenticación:**
✅ POST    http://localhost:3001/api/auth/login
✅ POST    http://localhost:3001/api/auth/register

🛠️ **Recursos Generados Automáticamente:**
✅ GET    http://localhost:3001/api/users
✅ POST   http://localhost:3001/api/users
✅ GET    http://localhost:3001/api/users/:id
✅ PUT    http://localhost:3001/api/users/:id
✅ DELETE http://localhost:3001/api/users/:id

✅ GET    http://localhost:3001/api/posts
✅ POST   http://localhost:3001/api/posts
✅ GET    http://localhost:3001/api/posts/:id
✅ PUT    http://localhost:3001/api/posts/:id
✅ DELETE http://localhost:3001/api/posts/:id

5. Autenticación

Registro

Para registrar un nuevo usuario, realiza una solicitud POST a /api/auth/register:

curl -X POST http://localhost:3001/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "123",
    "name": "Daniel",
    "email": "[email protected]"
  }'

Inicio de sesión

Para iniciar sesión, realiza una solicitud POST a /api/auth/login:

curl -X POST http://localhost:3001/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]"
  }'

6. Operaciones CRUD

Una vez autenticado, puedes realizar operaciones CRUD en los recursos. Por ejemplo, para obtener todos los posts:

curl -X GET http://localhost:3001/api/posts \
  -H "Authorization: Bearer <tu-token-jwt>"

¿Te gustó AuthJSON?

Si te gustó AuthJSON deja tu estrella en GitHub. Gracias!