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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nongos

v0.5.3

Published

[![JS Standard Style][standard-image]][standard-url] [![NPM version][npm-image]][npm-url]

Downloads

8

Readme

nongos

JS Standard Style NPM version

Project still under development!

An opinionated framework for fast prototyping RESTful APIs with Node.js based on the MEAN stack!

Install

npm i nongos -S

Basic usage

const nongos = require('nongos')

nongos.resource(
  'users',
  {
    name: {
      type: String,
      required: [true, 'required']
    },
    age: {
      type: Number,
      required: [true, 'required'],
      min: [10, 'at least 10']
    }
  }
)

nongos.start()

Done! Now you have a fully RESTful resource out of the box (CRUD). Give it a try:

GET http://localhost:1337/users
GET http://localhost:1337/users/:id
POST http://localhost:1337/users
PUT http://localhost:1337/users/:id
DELETE http://localhost:1337/users/:id

Configuration

Default configuration

{
  env: process.env.NODE_ENV ? process.env.NODE_ENV.trim() : 'development',
  port: process.env.PORT || 1337,
  db: {
    uri: 'mongodb://localhost',
    options: {
      useMongoClient: true
    }
  },
  logger: {
    transports: [
      new (winston.transports.Console)({
        colorize: true,
        timestamp: true
      })
    ]
  }
}

For more information on how to configure the path db.options, check the mongoose documentation.

For more information on how to configure the path logger, check the winston repository.

Changing the configuration

const nongos = require('nongos')

nongos.config({
  port: process.env.PORT || 3000,
  db: {
    uri: 'mongodb://myuser:[email protected]:59767/temp'
  }
})

// ...

Bootstrapping

If you want to override the default bootstrap you can use nongos.bootstrap(), just be aware that by doing so, the default bootstrap will no longer execute.

const nongos = require('nongos')

nongos.resource(
  'users',
  {
    name: String,
    age: Number
  }
)

nongos.bootstrap(() => {
  nongos.app.use(require('./my-middleware'))
})

nongos.start()

Resources

Validation

Because nongos uses mongoose you are able to validate your schema using the mongoose built-in rules or you can also create your own.

Check the full documentation at the mongoose website.

Methods

You can override or disable the default resource methods and also create new methods:

const nongos = require('nongos')
 
const {router, model} = nongos.resource(
  'users',
  {
    name: String,
    age: Number
  },
  {
    update: false,
    delete: false
  }
)

router.put('/:id', (req, res) => res.status(400).send({message: 'Nope!'}))

router.get('/foo', (req, res) => res.send('bar'))

router.post('/john-doe', (req, res, next) => {
  model.create({name: 'John Doe', age: 50}, (err, result) => {
    if (err) return next(err)
    res.send(result)
  })
})
 
nongos.start()

After these changes you will get:

GET http://localhost:1337/users // 200
GET http://localhost:1337/users/foo // 200 "bar"
GET http://localhost:1337/users/:id // 200
POST http://localhost:1337/users // 200
POST http://localhost:1337/users/john-doe // 200 {"__v": 0, "name": "John Doe", "age": 50, "_id": "5a3320b4e99a953ff07729a3"}
PUT http://localhost:1337/users/:id // 400 {"message": "Nope!"}
DELETE http://localhost:1337/users/:id // 404

Querying

You can use some advanced querying thanks to querymen.

For more information check its documentation.

GET http://localhost:1337/posts?page=2&limit=30
GET http://localhost:1337/posts?user=foobar&fields=title,content
GET http://localhost:1337/posts?limit=10&sort=-createdAt

Additional options

As seen above in the validation block, you can use the optional third parameter of nongos.resource() to override the default CRUD behavior.

In addition to that you can also configure the keywords feature powered by mongoose-keywords. Check its documentation for more information on how to do so.

const nongos = require('nongos')
 
const {router, model} = nongos.resource(
  'users',
  {
    name: String,
    age: Number
  },
  {
    list: true,
    create: true,
    read: true,
    update: false,
    delete: false,
    keywords: {
      path: ['name']
    }
  }
)

nongos.start()

Stack explained

License

MIT