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

next-json-server

v0.2.1

Published

Next.js App Router based lightweight JSON Server implementation

Readme

Next JSON Server

Test Build Lint

A lightweight JSON Server implementation based on Next.js App Router. Inspired by json-server, it provides a simple RESTful API based on JSON files.

Features

  • 💡 Next.js App Router support
  • 🚀 Simple setup
  • 📝 JSON file based data management
  • 🔄 RESTful API support
  • 🛠 Customizable endpoints
  • 🛢️ PostgreSQL support with Drizzle ORM

Getting Started

Using npm package

  1. Install the package
npm install next-json-server
  1. Create a db.json in your project root
{
  "posts": [
    { "id": "1", "title": "a title", "views": 100 },
    { "id": "2", "title": "another title", "views": 200 }
  ],
  "comments": [
    { "id": "1", "text": "a comment about post 1", "postsId": "1" },
    { "id": "2", "text": "another comment about post 1", "postsId": "1" }
  ],
  "users": [{ "id": "1", "name": "yuyakinjo" }]
}
  1. Generate JSON API route
npx next-json-server generate json

This will create /app/json/[...api]/internal.ts and /app/json/[...api]/route.ts files in your project.

  1. Start your Next.js development server
npm run dev
  1. Access your API at http://localhost:3000/json/posts

Using with PostgreSQL (Drizzle ORM)

  1. Generate PostgreSQL API route
npx next-json-server generate db/pg

This will create the following files:

  • /app/db/pg/[...api]/internal.ts - Internal utility functions
  • /app/db/pg/[...api]/route.ts - API route handler
  • /app/db/pg/schema/index.ts - Sample Drizzle schema file
  1. Configure your PostgreSQL connection in .env.local
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
  1. Customize your schema in /app/db/pg/schema/index.ts as needed

  2. Start your Next.js development server

npm run dev
  1. The server will automatically run migrations and seed data on startup

  2. Access your API at http://localhost:3000/db/pg/users (or any other table name defined in your schema)

Clone and Run

  1. Clone the repository
git clone https://github.com/yuyakinjo/next-json-server.git
  1. Install dependencies
cd next-json-server
bun install
  1. Start the development server
bun dev

API Endpoints

The following RESTful API endpoints are available:

Retrieving Resources

Navigate by path

  • GET /json/posts - Get all posts
  • GET /json/posts/1 - Get post with ID:1
  • GET /json/posts/1/comments - Get comments for post with ID:1
  • GET /json/posts/1/comments/1 - Get comment with ID:1 for post with ID:1

Using queries

  • GET /json/posts?id=1 - Get post with ID:1
  • GET /json/posts?id=1&id=2 - Get posts with ID:1 and ID:2
  • GET /json/posts?title=starwars - Get posts with title "starwars"
  • GET /json/posts?gt_views=100 - Get posts with views greater than 100
  • GET /json/posts?lt_views=100 - Get posts with views less than 100
  • GET /json/posts?gte_views=100 - Get posts with views greater than or equal to 100
  • GET /json/posts?lte_views=100 - Get posts with views less than or equal to 100
  • GET /json/posts?ne_views=100 - Get posts with views not equal to 100
  • GET /json/posts?in_views=100,200 - Get posts with views equal to 100 or 200

Creating Resources

  • POST /json/posts - Create a new post
{
  "title": "New post",
  "views": 0
}

Updating Resources

  • PUT /json/posts/1 - Update post with ID:1
{
  "title": "Updated post",
  "views": 150
}

Deleting Resources

  • DELETE /json/posts/1 - Delete post with ID:1

PostgreSQL API Endpoints

The following RESTful API endpoints are available when using the PostgreSQL integration:

Retrieving Resources

  • GET /db/pg/users - Get all users
  • GET /db/pg/users/1 - Get user with ID:1
  • GET /db/pg/posts - Get all posts
  • GET /db/pg/posts/1 - Get post with ID:1

Creating Resources

  • POST /db/pg/users - Create a new user
{
  "name": "New User",
  "email": "[email protected]"
}

Updating Resources

  • PUT /db/pg/users/1 - Update user with ID:1
{
  "name": "Updated User",
  "email": "[email protected]"
}

Deleting Resources

  • DELETE /db/pg/users/1 - Delete user with ID:1

Filtering and Pagination

  • GET /db/pg/users?limit=10&offset=0 - Paginate users
  • GET /db/pg/users?name=John - Filter users by name
  • GET /db/pg/posts?authorId=1 - Get posts with authorId:1

Response Examples

GET /json/posts

[
  {
    "id": "1",
    "title": "a title",
    "views": 100
  },
  {
    "id": "2",
    "title": "another title",
    "views": 200
  }
]

Status Codes

  • 200 - Request successful
  • 201 - Resource created successfully
  • 204 - Resource deleted successfully
  • 404 - Resource not found

CLI Commands

  • npx next-json-server generate json - Generate JSON API route files
  • npx next-json-server generate db/pg - Generate PostgreSQL API route files (with Drizzle ORM)
  • npx next-json-server help - Show help message

Usage in Development Environment

  1. Clone the repository
git clone https://github.com/yuyakinjo/next-json-server.git
  1. Install dependencies
cd next-json-server
bun install
  1. Start the development server
bun dev

Running with Docker

You can also run it using Docker:

docker compose up -d

License

Released under the MIT License. See LICENSE for details.