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

autonodeapi

v1.0.8

Published

For auto-generating APIs

Readme

🚀 autonodeapi Documentation

autonodeapi is a powerful Node.js package that automates the generation of CRUD APIs for Mongoose models. It also generates a Swagger documentation endpoint for easy API reference.


📌 Features

Automatically generates CRUD APIs for Mongoose models

Supports dynamic model creation with user-defined fields

Generates a fully documented Swagger API at /api/docs

Reduces boilerplate code, making development faster

Easy integration with existing Express applications


📌 Installation

First, install the required dependencies using npm:

npm install autonodeapi

⚙️ Usage

Run the following command to generate your API:

npx generate-auth //to login, logout, signup functionality (once)
npx generate // when need to create api for a model run this command

1️⃣ Provide Model Name

After running the command, it will ask for a model name. Example:

Enter model name: user

(The model name should be in singular, and it will be created in the /models directory.)

2️⃣ Provide Model Fields

Next, enter the fields for your model in the format:

fieldName:DataType

Supported Data Types: String, Number, Boolean, Date, Array, Object

Example:

Enter fields (comma-separated): username:String, password:Number

This will create a User model with:

const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
  username: { type: String, required: true },
  password: { type: Number, required: true }
});

module.exports = mongoose.model("User", UserSchema);

📌 What Happens Next?

✅ A Mongoose Model is created in /models

✅ A Controller is created in /controllers

✅ A Route is created in /routes

✅ A Swagger documentation file is updated


📌 Register Routes

You can skip this next steps if you used the command - npx generate-auth

To make the generated API work, register the routes in index.js or server.js.

1️⃣ Import Routes

import routes from "./routes/index.js";
import swaggerRoutes from "./swagger.js";

2️⃣ Use Routes in Express App

app.use("/api", routes);
app.use("/api", swaggerRoutes);

📌 View API Documentation

Once everything is set up, you can view your API documentation at:

http://localhost:<PORT>/api/docs

(Replace <PORT> with your actual port number, e.g., 3000.)

This will show a list of all generated API endpoints.

✅ Generated Endpoints

For a model named User, the following CRUD endpoints will be available:

| Method | Endpoint | Description | | --- | --- | --- | | POST | /api/user | Create a new user | | GET | /api/user | Get all users | | GET | /api/user/:id | Get user by ID | | PUT | /api/user/:id | Update user by ID | | DELETE | /api/user/:id | Delete user by ID |


🎯 Example API Request

To create a new user, send a POST request to:

POST http://localhost:3000/api/user

With a JSON body:

{
  "username": "john_doe",
  "password": 123456
}

🎯 Example API Response

A successful response will return:

{
  "success": true,
  "data": {
    "_id": "65fa1b2e3d5f2b001fdd1234",
    "username": "john_doe",
    "password": 123456,
    "createdAt": "2025-03-14T12:00:00.000Z"
  }
}

🔗 Registering Routes

To use the generated routes, add them to your index.js or server.js file:

import express from "express";
import routes from "./routes/index.js";
import swaggerRoutes from "./swagger.js";

const app = express();

app.use(express.json()); // Middleware for JSON parsing

// Register API routes
app.use("/api", routes);

// Register Swagger documentation route
app.use("/api", swaggerRoutes);

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
  console.log(`🚀 Server running on http://localhost:${PORT}`);
});

📜 Viewing API Documentation

Once the server is running, open your browser and visit:

http://localhost:<PORT>/api/docs

This will display a Swagger UI showing all available API endpoints.

🎯 Example Swagger UI:

  • /api/users (GET) → Fetch all users
  • /api/users/:id (GET) → Fetch a user by ID
  • /api/users (POST) → Create a new user
  • /api/users/:id (PUT) → Update an existing user
  • /api/users/:id (DELETE) → Delete a user

🛠️ Customization & Extensions

Since autonodeapi generates standard Express routes, controllers, and models, you can customize them as needed.

For example, to add authentication, middleware, or custom business logic, edit the generated controller files inside the controllers/ directory.


🎯 Why Use autonodeapi?

Saves time by auto-generating boilerplate CRUD APIs

Easy to set up and integrate with existing Express projects

Built-in Swagger documentation for better API management

Fully customizable and scalable


🚀 Start Building APIs in Seconds!

This tool saves hours of work by automatically generating:

Models

Routes

Controllers

Swagger API documentation

Just run:

npx generate-auth
npx generate

Provide a model name and fields, and you're ready to go! 🎉🔥