Skip to content

Repository files navigation

Parts Framework

A lightweight NodeJS Framework

Description

Quickly create node JS APIs

This framework onyl uses Mongo as database, for now.

Usage

Start with node --harmony app.js

Creating a model

Models are made with the help of Mongoose Schemas.

How to

Create a file with the name of the model in the models/ folder As an example you have the models/user.js. This will create a model named "User" (user.js => User)

Creating a controller

How To

Create a file in the controllers folder.

Example

// User Controllermodule.exports={name: 'User',// the name of the controllerdata: {// object of needed data, optionalsomeData: true},methods: {all: function(req,res){res.json({users: []})}},needs: ['SomeController']}

Controller parts

Name

The name of the controller

Data

Object containing data

data: {property: true}

This will be available as Controller.property , so don't use the same name for data and methods

Methods

Self explanatory

Needs

The framework loads all controllers with data and methods and then puts the dependencies in every one of them. In this case, other dependencies are controllers that may be needed.

needs: ['Auth']

This will load the Auth controller in Controller.authController

Creating routes

How to

You just have to edit the routes/http.js file. Out Route method is just a wrapper for Express app.method for now, we'll extend to express Router later.

Example

Route.get('/users','User@getAll');

You can user Route.get exactly as you would use Express app.get. The only difference is that you can also use 'Controller@method' instead of a function.

Config file

You should rename the example.config.js to config.js. This file contains a example config file with all the info that Parts need to run. You can add other keys to this config and they will be available.

varconfig=use('Config');console.log(config.http.port);// gives exactly thatconsole.log(config.http.asd);// gives undefinedconsole.log(config.getValue('http.asd'));// gives nullconsole.log(config.getValue('http.asd','aa'));// gives 'aa'

Using the 'use' function

varConfig=use('Config');// This will return the ConfigvarRoute=use('Route');// This will return Route object (the methods are the http methods from app in express)varUser=use('User');// This will return the User controller. No, this is not predefined. Every capitalized string (except Config and Route) will be identified as a controller name.vargetAll=use('User@getAll');// This will return getAll method / property of the User ControllervarUser=use('#User');// This will return the Mongoose Model named 'User';

About

Lightweight Node JS Framework

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages