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

administrate

v0.7.3

Published

Middleware that provides an admin backend site for Express 4.x and Mongoose models

Downloads

72

Readme

#Administrate Connect-style middleware that dynamically generates an admin web app from Mongoose models. Compatible with Express 4.x+

##Installation

npm install administrate

##How To Use Administrate works like any other piece of Express 4.x middleware. Usage is as simple as:

const administrate = require('administrate');

const options = {
    modelPath: '/app/models',
    authMiddlewareFn: passport.middleware // Whatever middleware you use on your routes to verify a request is coming from an admin user
};

app.use('/admin', administrate(options));

##Options Administrate has a number of options. While none are required, you will need to set at least two as in the example above.

string: modelsPath: A string to the path of your mongoose models directory. All .js files in this folder will be parsed as models. Defaults to /app/models

array OR object: models: Depending on how you load models in your app, you may run into compilation errors from Mongoose. If this happens, pass your mounted models in an array or object.

function: authMiddlewareFn: A middleware function to use to verify requests. IMPORTANT: If no middleware function is provided, admin routes will be exposed to the public, allowing anyone to edit/remove/generally mess up your databse. This is bad. A good authentication/middleware library to use is Passport.js.

string: appName: The name of your app. Displayed in the admin site header. Defaults to Administrate

object: customListColumns: An object with keys corresponding to lowercase model names as registered in mongoose.model(). Each key is an array containing a list of schema paths to display in the admin list view. The list columns will be rendered in the order of keys. The id path will always be displayed and will always appear in the first column of every list.

Example:

const customListColumns = {
  user: ['email', 'name', 'createdAt', 'updatedAt']
};

string: logoutLink: The path to your app's logout route. If this is provided, then the admin site header will display a logout link. Example: '/logout'. Defaults to undefined

[string]: pathsBlacklist: Suppress certain paths from your schemas from appearing in the admin interface. This is useful if you have any hidden metadata paths that aren't meant to be edited by humans. By default, this filters out paths auto-generated by Mongoose. Adding your own values will be combined with the existing list.

string: viewsPath: A custom path to JADE templates to render for admin. This is if you want to overwrite the default templates with your own. However, keep in mind that you will need to properly populate the local variables for templates to work. Changing this value is not recommended without first studying the built-in templates in /templates.

##Schema modifiers Administrate supports a few options that affect how Schema paths are displayed and edited in the admin. Slip these into the schema path options and they will automatically be applied in the admin.

###Filter Support Add filter: true to a schema path to make it filterable in the admin view.

###Textarea Support Add extended: true to your String schema paths to display a textarea in the admin interface instead of a single text input. Useful for editing blog posts and other larger bodies of text.

###Hidden Paths Add hidden: true to any Schema path to hide it from being displayed in the admin.

###Read-only Paths Add edit: false to any Schema path to have a path disabled on the front-end.

##TODO Tests. They don't exist.

##Changelog

04-01-2016: Many a bug squashed. Sub-documents now supported. Default sorting by createdAt if available in schema.

03-31-2016: Added filtration, improved sorting and pagination, frontend bug fixes

03-29-2016: Updated list view with pagination and sorting.