Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

microframework

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microframework

Micro framework is a bundle of express.js, mongodb ODM, validator, dependancy injection framework and restful controllers for your apps using Typescript

  • 0.5.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
581
decreased by-21.59%
Maintainers
1
Weekly downloads
 
Created
Source

MicroFramework

Micro framework integrates popular libraries like express.js, Mongodb ODM, validator.ts, controllers.ts, event-dispatcher.ts and others for use in your Typescript application. Framework ships by default dependency injection framework and configuration framework to make all modules to work like a sh

Notice

Library is under active development and API may change from version to version. Please consider it before using this library.

Installation

You use framework with one or more the available modules. Lets say you want to use express.js, Mongodb ODM, validator, event-dispatcher and restful controllers.

  1. Install npm modules:

    npm install microframework microframework-express microframework-typeodm microframework-controllers.ts microframework-validator.ts microframework-event-dispatcher.ts configurator.ts controllers.ts typedi typeodm validator.ts --save

  2. Use typings to install all required definition dependencies.

    typings install

  3. ES6 features are used, so you may want to install es6-shim too:

    npm install es6-shim --save

    you may want to require("es6-shim"); in your app

Usage

  1. Create src/app.ts:

    import {MicroFrameworkBootstrapper} from "microframework/MicroFrameworkBootstrapper";
    import {ExpressModule} from "microframework-express/ExpressModule";
    import {ControllersTsModule} from "microframework-controllers.ts/ControllersTsModule";
    import {TypeOdmModule} from "microframework-typeodm/TypeOdmModule";
    import {ValidatorTsModule} from "microframework-validator.ts/ValidatorTsModule";
    import {EventDispatcherTsModule} from "microframework-event-dispatcher.ts/EventDispatcherTsModule";
    
    new MicroFrameworkBootstrapper({ srcDirectory: __dirname })
        .registerModules([
            new ExpressModule(),
            new TypeOdmModule(),
            new ControllersTsModule(),
            new ValidatorTsModule(),
            new EventDispatcherTsModule()
        ])
        .bootstrap()
        .then(result => console.log("Module is running. Open localhost:3000"))
        .catch(error => console.error("Error: ", error));
    
  2. Create configuration file config/config.json (note: its not in the same dir where your source is, folder is near your package.json file):

    {
      "express": {
        "port": "3000",
        "bodyParser": {
            "type": "json"
        }
      },
      "typeodm": {
        "connection": {
          "url": "mongodb://localhost:27017/microframework-sample"
        }
      }
    }
    
  3. Now create your first controller, lets say QuestionController: src/controller/QuestionController.ts:

    import {JsonController, Get} from "controllers.ts/Annotations";
    import {Response, Request} from "express";
    
    @JsonController()
    export class QuestionController {
    
        @Get("/questions")
        all(): any[] {
            return [
                { title: "Which processor to choose?", text: "Which processor is better: Core i5 or Core i7?" },
                { title: "When new star wars gonna be released?", text: "When star wars gonna be released? I think in december" }
            ];
        }
    }
    
  4. Run your app and open http://localhost:3000/questions in browser. You should see list of your questions.

Available Modules

Todos

  • cover with tests
  • more documentation and examples
  • more modules
  • add ability to include other configs by include path in the object?
  • add yo generator
  • good to have todo mvc sample

FAQs

Package last updated on 02 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc