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

ngnode

v2.0.7

Published

Simply and Quickly build your MEAN application

Downloads

4

Readme

中文版README

ngNode

Simply and Quickly build your MEAN application.

Features

  • Real time MEAN application.
  • Simply and quickly build web application with simple model config object, anything else need to do? no! nothing else!
  • Auto generate all things including mongodb collection, CRUD api, datatable, sorting, paging, searching, editing data, etc.
  • An User model within it, and with passport.js authentication

Before You Begin, you may want to know:

This library runs under MEAN, you can find some infomation about MEAN below.

Usages

dependency:

"ngnode": "2.0.5"

install dependency

npm install

make a config object and call ngNode as function

var config = {
	appName : "testapp",
	mongodConnection : "mongodb://localhost:27017/ngnode",
	on : {
		"someaction" : function (req, res, model, cb) {
			// hook all models here you want when "someaction" execute.
			// and can define in the model config as well
			// see the model config below for detail
		}
	}
};
require("ngNode")(config);

and save as app.js and run

node app.js

guess what? a MEAN application you have built! it is really simple, is it?

How simply ngNode be?

with simple config object above, we can quickly build a MEAN application, and a default model "user" in it.

and you can make your own model as well, once a custom model is created and app start, what ngNode will do with the custom model?

In server side

  1. mongodb model collection is created with the schema which define in model config
  2. auto create service with crud actions
  3. auto create crud routers
  4. initialize data from initData config when the app start
  5. custom hooks inject in crud actions

In client side

  1. custom fields of collection with title, sortable, queryable, edit type.
  2. auto generate data table with custom page size and pagination
  3. auto generate "create", "edit" and "remove" link, client side routers and ajax request as well
  4. display field value in either default value or return form custom "render" function
  5. multi edit types are support, including simple text, textarea, datepicker, checkbox, date list.

How to define custom model

ngNode will try to find models in your app's "/models" folder

the follow model module is what the custom model config look like:

module.exports = function () {
	return {
        name: "blog", // model name, would be used as the name in mongodb collection
        schema: { // collection's fields schema defined
            title: { // field name in mongodb
                text: "Title", // display in header of datatable
                type: String, // define type in mongoose
                editType : "textarea" // [optional] edit type, default is simple text
                editable : true, // [optional] can edit? default is true
                sortable: true, // [optional] can sort? default is false
                render : function(data){ // [optional] custom field's content to display
                                // data : field's content
                    // return something you want, or return data with do nothing as default do
                }
            },
            ... other fields
        }
        defSortField: "title", // default sort field
        queryFields: ["title"], // fields you want to query when searching
        defaultPageSize: 15, // default page size
        on: { // hook only in this model, if you want to hook all model, this should define this in application config's "on"
            "beforeCreate": function (req, res, model, cb) {
                // do something you want before create
                cb(model); // callback and continue to create the "model"
                cb({err : "something wrong and i don't want to continue to create this 'model'"});
                // so avoid the model object has the key "err" when you want to continue the action
            }
        },
        initData : function(mongoose){
            // this function will be called when the app is started
        }
    }
};

A model config which define in node.js module style can use in browser? how?

When the app start, ngNode will pack the custom model module into browser's object by use browserify, it is awesome, is it?

dependencies in ngNode

  • express : ngNode is a framework of MEAN, so express is included
  • mongoose : my first choice mongodb ORM
  • passport: I use passport as authentication
  • express-session : use express-session to maintain user authentication
  • connect-mongo : and use mongodb as session store in express-session
  • browserify : model module used in server side and browser side, browserify definitely
  • bcrypt : user model use bcrypt to encode password when create user, and compare password when user login

Sample

An ngNode's sample can be found in ngNode-sample

  • git clone and run npm install and run npm start
  • visit in chrome: http://localhost:9527/user or http://localhost:9527/blog or http://localhost:9527/yourownmodel when you add "yourownmodel"
  • login with [email protected]/test