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

mongoose-restify-server

v0.0.2

Published

Mongoose restify server configured by settings file.

Downloads

7

Readme

Mongoose Restify Server

A quick API server setup using mongoose and restify. Configuration files are used to setup model, routes and restful services.

Installation

npm install --save mongoose-restify-server

Test

npm test

Usage

index.js


var server = require('mongoose-restify-server');
server.lift(require('./config.js'), function() {
    console.log('Server lifted.');
});

where the configuration settings can be defined in config.js

module.exports = {
    port: 8085,
    mongo: 'mongodb://localhost/test',
    model: __dirname,
    controller: __dirname,
    routes: {
        blog: {}
    }
}

Here the blog is defined using Mongoose model in blog.js


var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Mixed = Schema.Types.Mixed;
module.exports = {
    fields: {
        title: { type: String },
    },
    options: {
        collection: 'blog',
        versionKey: false,
        timestamps: {},
        runValidators: false
    },
    methods: {},
    indexes: {},
    virtuals: {}
}

Since we use the module to do all the heavy lifting for us, we can just leave empty in the blogController.js


module.exports = {
};

That's it, if you fire the server, you should see a restful resources for blog on port 8085.

More

The routes in the config.js can have non-restful calls,


var config = {
    port: 8085,
    routes: {
        /**
         * GET call
         */
        get: {
            path: '/get',
            GET: httpCall,
        },
        /**
         * POST call
         */
        post: {
            path: '/post',
            POST: httpCall,
        },
        /**
         * Bundle call
         */
        bundle: {
            path: '/bundle',
            GET: httpCall,
            POST: httpCall,
        },
        /**
         * REST call
         */
        rest: {
            path: '/rest',
            REST: {
                query: httpCall,
                detail: httpCall,
                insert: httpCall,
                patch: httpCall,
                del: httpCall
            }
        },
        /**
         * Group call
         */
        group: {
            path: '/group',
            items: {
                get: {
                    path: '/get',
                    GET: httpCall,
                },
                post: {
                    path: '/post',
                    POST: httpCall,
                },
                bundle: {
                    path: '/bundle',
                    GET: httpCall,
                    POST: httpCall,
                },
                rest: {
                    path: '/rest',
                    REST: {
                        query: httpCall,
                    }
                }
            }
        },
        /**
         * Mixed call
         */
        mixed: {
            path: '/mixed',
            items: {
                get: {
                    path: '/get',
                    GET: httpCall
                }
            },
            REST: {
                query: httpCall,
                insert: httpCall,
            }
        }
    }
};

In that case, you do not need to specify the mongo, model and controller, because each httpCall can be a simple express route function


var httpCall = function(req, res, next) {
    res.send('Hello server');
    next();
};

In case you want to organize routes using controller actions, you can do


var config = {
    port: 8085,
    controller: '../../test/fixture',
    routes: {
        /**
         * GET call with controller
         */
        ctrl: {
            path: '/ctrl',
            controller: 'index',
            GET: 'index',
        },
        /**
         * REST call with controller
         */
        rest: {
            path: '/rest',
            controller: 'rest',
            REST: ['query', 'detail']
        },
        /**
         * Group call with controller
         */
        group: {
            path: '/group',
            controller: 'index',
            items: {
                'index': {
                    path: '',
                    GET: 'index'
                },
                'debug': {
                    path: '/debug',
                    POST: 'debug'
                },
                'rest': {
                    path: '/rest',
                    REST: ['query', 'detail']
                }
            }
        },
    }
};

where the method value (ex. GET) is replaced by the action name if controller is specified.