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

tongoose

v0.6.1

Published

Auto-generate TypeScript interfaces from Mongoose schemas!

Readme

Tongoose

📘 Auto-generate TypeScript interfaces from Mongoose schemas!

Usage

  • Remotely
npx tongoose ./path/to/mongoose/model(s/)
  • Locally (recommended)
npm install --global tongoose
# or
yarn global add tongoose

and run

tongoose ./path/to/mongoose/model(s/)

That's it! Now just integrate the generated interfaces with your Mongoose Schemas!

Don't know how? Head over to the From 0 to hero section - you'll set up a sample TypeScript + Babel project & will learn how to integrate TypeScript with mongoose Schemas!


Table of contents

From 0 to hero (you'll love it)

Note - the code is available at /tongoose/TypeScript-Babel-Starter

Warning - this is currently out-of-date. We'll update this tutorial shortly.

Set up a simple TypeScript + Babel project

git clone https://github.com/Microsoft/TypeScript-Babel-Starter.git
cd TypeScript-Babel-Starter
  • Install dependencies
npm i mongoose
npm i --save-dev @types/node @types/mongoose @types/mongodb
  • buckle up
rm src/index.ts
mkdir -pv src/models/
touch src/models/User.ts
  • open src/models/User.ts file in your favorite text editor

Create a mongoose schema

// src/models/User.ts
import mongoose from "mongoose";

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

const User = mongoose.model("User", UserSchema, "users");

export = User;
  • Great. Now install tongoose & take a look at the --help message:
npm i -g tongoose
tongoose
Usage: tongoose ./path/to/models/ [--opt [arg]]

Options:
  -s, --src, --source  [required] [selected by default] relative path to
                       mongoose models' directory

  -o, --output         [auto=source/index.d.ts] relative path for index.d.ts
                       type definition output

  -n, --noFormat       [auto=false] do not format the type definition files

  -d, --debug          [auto=false] enables debugging - generates .tongoose/
                       directory with separate type definition, raw & clean
                       json files for each schema

  -v, --version        Show version number
  -h, --help           Show help

Examples:
  tongoose ./src/models
  tongoose ./src/models --noFormat
  tongoose --help

Generate the type definition file!

  • Run tongoose with the path to our src/models/ directory
tongoose src/models/
⚡️ Tongoose finished
📂 Created `.tongoose` directory for manual debugging (you can safely delete it)
📘 Main `index.d.ts` file placed in 👉 `src/models/index.d.ts`
  • open the generated src/models/index.d.ts file & take a look!
import mongoose from "mongoose"
import { ObjectId } from "bson"; // `npm i --save-dev @types/mongodb`

// Notice the difference between `IUserModel` & `IUser`!
export interface IUserModel extends IUser, mongoose.Document {}
export interface IUser {
	username?: string;
	email: string;
	password: string;
}

Such Success! 😱 Much Greatness! 😍 Now let's try to apply & use the generated type interface

  • head back to src/models/User.ts
  • make the following changes:
// src/models/User.ts
import mongoose from "mongoose";
+import { IUserModel } from './index.d';

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

-const User = mongoose.model("User", UserSchema, "users");
+const User = mongoose.model<IUserModel>("User", UserSchema, "users");

export = User;

Awesome! Now let's test it!

  • Create a src/test.ts file
touch src/test.ts
  • open it & add the following code:
// src/test.ts
import User = require("./models/User");

const user = new User({});
  • Start typing user<dot> and see what comes up!

Plot twist:

  • You can see the email field right at the bottom together with mongoose.Document's fields. Everything (hopefully) worked great!

  • Congratulations!


Back to Table of Contents ☝️


Our Roadmap

Contributing

Contributions are welcome! Please fork the repo, modify it & submit a pull request!

The Roadmap is a good place to start 😃

Developers

  • Kipras Melnikovas - author - /sarpik 😎

License

MIT