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

mkres

v2.0.1

Published

[![npm](https://img.shields.io/npm/v/mkres.svg) ![npm](https://img.shields.io/npm/dm/mkres.svg)](https://www.npmjs.com/package/mkres)

Readme

Introduction

npm npm

Best way create Restful API in express and mongoose

install

const mongoose = require('mongoose')
require('mkres').setMongoose(mongoose)

Smart Select Attribute

const {parseSelect} = require('mkres')
const User = require('mongoose').model('User')

let {select,populate} = parseSelect(User, 'username,address{street,city,users},...')
let users = User.find({}).select(select).pupulate(populate)

console.logs('>> Users: ', users)

Select text format

  • field_1,field_2,field_n : Select declared fields
  • field_1,field_2,...: Select declared fields and all other fields in schema
  • field_1,field_2{ child_field_1, child_field2} : Populate and select child_field
  • field_1,field_2{child_field,...} : Populate and select child field and all other child fields of field_2
  • "..." : Select all other fields

Populate and Deep Populate

We can populate by format:

field{} // Populate and select all child field 

or

field{f1,f2} // Populate and select declared child field

or

field{...,f1{}} // Populate and select all child field and populate child field 

We can deep populate:

field{f{ff{fff1,fff2},...}}

Spread "..." is select all other fields

Smart Find

const {parseFind} = require('mkres')
const User = require('mongoose').model('User')

let findQuery = parseFind('age <= 3 or (age >=5 and age <9)')
let users = User.find(findQuery)

console.logs('>> Users: ', users)

Ussage

Prepare model

User

const mongoose = require('mongoose')
const Schema = mongoose.Schema

let UserSchema = new Schema({
  username: {
    type: String
  },
  firstName: String,

  age: Number,

  address: {
    type: Schema.Types.ObjectId,
    ref: 'Address'
  },

  addresses: [
    {
      type: Schema.Types.ObjectId,
      ref: 'Address'
    }
  ]

}, {
  timestamps: {
    createdAt: true,
    updatedAt: true
  }
})

const User = mongoose.model('User', UserSchema)
module.exports = User

Address

const mongoose = require('mongoose')
const Schema = mongoose.Schema

let ModelSchema = new Schema({
  street: String,
  city: String
})

const Model = mongoose.model('Address', ModelSchema)
module.exports = Model

findById

const express = require('express')
const {makeFindById} = require('mkres')

const app = express()
const router = express.Router()

makeFindById({
    router: router,
    model: User
})

app.use('/users',router)

Use

GET /users/?select=-_id,username,address{city},address{street}

Params:

  • select: select option, return only declared field
  • extra: return extra declared field, ( use when you want populate some field but select all field)

find

const express = require('express')
const {makeFind} = require('mkres')

const app = express()
const router = express.Router()

makeFind({
    router: router,
    model: User,
    defaultLimit: 10 // for pagination
})

app.use('/users',router)

Use

GET /users/?limit=10&offset=0&page=1&select=username,address{city}&find=(age>=1 and age<=3>) or (age > 5) 

Params:

  • limit: size of one page
  • offset: offset of first item
  • select: select option, return only declared field
  • extra: return extra declared field, ( use when you want populate some field but select all field)
  • find: simple condition for find item in mongo
  • one : return one item

create

const {body} = require('express-validator/check')
const express = require('express')
const {makeCreate} = require('mkres')

const app = express()
const router = express.Router()

makeCreate({
    router: router,
    model: User,
    validators: [
        body('username').not().isEmpty().withMessage('Kkong duoc de trong')
    ]
})

app.use('/users',router)

Use

Post /users/?select=username,age,-_id

Params:

  • select: select option, return only declared field
  • extra: return extra declared field, ( use when you want populate some field but select all field)

update

const {body} = require('express-validator/check')
const express = require('express')
const {makeUpdate} = require('mkres')

const app = express()
const router = express.Router()

makeUpdate({
    router: router,
    model: User,
    validators: [
        body('username').not().isEmpty().withMessage('Kkong duoc de trong')
    ]
})

app.use('/users',router)

Use

PUT /users/:id?select=username,age,-_id

Params:

  • select: select option, return only declared field
  • extra: return extra declared field, ( use when you want populate some field but select all field)

delete

const express = require('express')
const {makeDelete} = require('mkres')

const app = express()
const router = express.Router()

makeDelete({
    router: router,
    model: User
})

app.use('/users',router)

Use

DELETE /users/:id

Development

docker-compose up