Catalog npm
Back to packageRELEASE DETAILS

0.0.9

npm

10tcl

CRUD over express and mongodb

10tclappcrudtentacleweb
Published14 Dec 2012
Direct dependencies8
Transitive dependenciesNot calculated

README

Current package documentation

What is it?

10tcl is a CRUD plugin that will add default routes to your express app, that read and store data in your mongodb.

How is it?

It works! ...mostly. Right now I could not recommend it. Give it a few months before serious usage. It has some limitations and misconceptions, and it is not getting better soon.

Install

$ npm install 10tcl

Config

A config file must contain:

module.exports = {
    // used as title for your pages
    brand: 'Day of the Tentacle IS HERE!',
    // used to assemble the connection string to your mongodb instance
    db: { 
        usr: 'Purple',
        pwd: 'Tentacle',
        srv: 'ds044356.mongolab.com:49842',
        db:  'day_of_the_tentacle',
        par: 'auto_reconnect'
    },
    // static admin user to allow first login
    admin: { usr: 'admin', pwd: 'ElGranSecreto', name: 'Admin', role: 'admin'}
    // __dirname of your root
    root: root, 
    // if not informed it defaults to 'root/models', 'root/controllers' and 'root/views'
    pathToCtrls: '/app/controllers',
    pathToModels: '/app/models',
    pathToViews: '/app/views',
    pathToValidator: 'app/models/validator'
}

Use

// __dirname will be the root to locate folders indicated in pathTo... properties
var app = require('10tcl').attack(__dirname, '/config/yourConfigFile')
app.listen(yourPortHere)

10tcl attack results in an express app configured with routes based on your models and controllers.

Database

app.db contains a connection to your database. It was done by using Mongoskin and the credentials on the config object.

Controllers

Every .js file under your controllers folder was required, receiving (app, base, config).

An example of controller file would be:

module.exports = function(app, base, config){

    function hello(req, res){
        res.send('hello world')
    }

    app.get('/hello', base.auth, hello )

    // will be used to create a menu
    return {name: 'hello', label: 'Hello World'}

}

Models

Every .js file under your models folder was required as well, no arguments. Each binded to app.db by the model.name property, so now app.db[modelNameHere] points to a collection capable of restfull crud.

An example of model would be:

module.exports = {
    // model and db collection name
    name: 'victims',
    // Title for pages and menu
    label: 'Victims',
    // used with mustache to format list and drop down descriptions 
    format: 'Victim {{name}} {{lastName}}',
    // fields to format and forms (see next topic)
    fields: [
        { name: 'name', label: 'Nome', type: 'string', checks: ['hasValue'] },
        { name: 'lastName', label: 'Sobrenome', type: 'string' }
    ],
    // create route '<your-site>.com/victims' pointing to 10tcl CRUD
    routeTo10tcl: true,
    // read the entire collection into the app, changes it before persisting
    keepInCache: true,
    // restrict access to users with one of these roles
    onlyFor: ['admin'],
    // used if you run 'node myApp.js mock'
    mock: [
        {name: 'Mussum', _id: '508e0077d42bd6182f000001'},
        {name: 'Zacarias', _id: '508e0077d42bd6182f000002'},
        {name: 'Dedé', lastname: 'Santana', _id: '508e0077d42bd6182f000003'},
        {name: 'Didi', lastname: 'Mocó', _id: '508e0077d42bd6182f000004'}
    ]
}

Field types

10tcl understands: string, number, email, tel, date, html, text, reference (type: 'reference', to: 'criminal') Each will result in a different html element and layout. A field type different from the above will result in a regular input field.

Validation

10tcl modelValidator provides type associated checks, that are automatically executed on POST/PUT transactions. Other than that, a field can contain a property checks: ['hasValue', ...] Each string in checks array will trigger the correspondent function of the modelValidator. Defining pathToValidator, you can implement your own validator that will be required instead of the 10tcl one.

Users

User and Profile are pre-loaded models that provide access control. The config property "admin" provides a proto user for the first login.

i18n

Nop... sorry. And I'm outputting static texts in PT-BR. Not happy with any package I've tried. Want to keep texts in a cached db for online editing and translation.

CRUD

The views are made with bootstrap, jquery, and some home-made binding (Angular was just making me angry). In mobile they are much simpler, made with jquerymobile and jquery. The decision between mobile and desktop is made by reading request headers.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 8

Native requirements
8 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
express
Environment
{
  "local_name": "express",
  "alias": false,
  "peer_metadata": null
}
3.0.xruntime
mongoskin
Environment
{
  "local_name": "mongoskin",
  "alias": false,
  "peer_metadata": null
}
0.3.xruntime
mustache
Environment
{
  "local_name": "mustache",
  "alias": false,
  "peer_metadata": null
}
*runtime
jade
Environment
{
  "local_name": "jade",
  "alias": false,
  "peer_metadata": null
}
*runtime
sugar
Environment
{
  "local_name": "sugar",
  "alias": false,
  "peer_metadata": null
}
1.3.xruntime
validator
Environment
{
  "local_name": "validator",
  "alias": false,
  "peer_metadata": null
}
0.4.xruntime
less
Environment
{
  "local_name": "less",
  "alias": false,
  "peer_metadata": null
}
*runtime
less-middleware
Environment
{
  "local_name": "less-middleware",
  "alias": false,
  "peer_metadata": null
}
*runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "f669efc5a228773fe67effc81e06b5e31b4303a8",
  "tarball": "https://registry.npmjs.org/10tcl/-/10tcl-0.0.9.tgz",
  "integrity": "sha512-Uti3hgJ+P++1xcr2OtefOwUHfq7jl/KK5QrIKK/xoqBEOWEhpv6tePB6J2dY+1jMxTnnrtEi/LaABIh2N7QL6w==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIGNZS3u/7kCRiCKo3j3zgqH0sf4lGD6mWh5maaflnkZnAiA1aqFIBV1xs2cqSq4qvWB+9Mw5wDQKQjz+DlXQ2ULbTQ=="
    }
  ]
}

Repository

PENDING
superpeixeboi/10tcl

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:01 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:ce18dcae14264bd5efbe28d1a99263060d2292f0bad62428a92b1f9a8d1df32a

Other collected versions

0.0.1013 Feb0.0.810 Dec0.0.75 Dec0.0.65 Dec0.0.52 Dec0.0.429 NovView all collected versions →