New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kratos

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kratos

Powerful full stack framework using the strength of the JavaScript ecosystem

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59
increased by11.32%
Maintainers
2
Weekly downloads
 
Created
Source

Kratos NPM Version NPM Downloads License Build Status

Powerful full stack framework using the strength of the JavaScript ecosystem

PLEASE NOTE: Kratos API could break and change drastically until v1.0.0.

Kratos isn't your typical full stack framework. It doesn't try to do everything for you. It's built on top of Express and sets the boilerplate for sensible middleware and adds some extra functionality on top.

Install

$ npm install -g kratos

Getting Started

You can create a kratos application skeleton by issuing the following

$ kratos new myapp

Once your skeleton application is created you can cd myapp and start it by running

$ kratos start

Usage

Because Kratos is built on top of Express you have access to everything it has to offer. On top of that the boilerplate to get started is very simple. Here's an example Kratos app

var app = require('kratos');

app.get('/', function(req, res) {
    res.send('Welcome to Kratos!');
});

app.run();

When you do $ kratos start in your terminal, you should see something similar to this

$ kratos start

Kratos app running at http://localhost:1337 in development mode.

Config Loader

Kratos has a built in config loader that allows you to have a config file per module, or whatever you want, and load one based on environment to merge into production config also.

Take for example you have app/config/app.js with the following contents:

module.exports = {
  name: 'My Production Site'
};

This is your production config file for the app. Then you create a file called app/config/development/app.js with the following:

module.exports = {
  name: 'My Development Site'
};

Then you set NODE_ENV=development Then when you use the config module:

var config = require('kratos').Config();

config('app.name'); // My Development Site

But when set NODE_ENV=production then this will result:

var config = require('kratos').Config();

config('app.name'); // My Production Site

Resource Routing

One of the things that Kratos brings to the plate is resource routing. This allows you to step back from the mundane task of setting up RESTful routes for your app. Here is an example app using resource routing

var app = require('kratos');
var resource = require('kratos').Resource();

var controller = {
    index: function(req, res) {
        res.send('responding to GET /');
    },
    create: function(req, res) {
        res.send('responding to GET /create');
    },
    store: function(req, res) {
        res.send('responding to POST /');
    },
    show: function(req, res) {
        res.send('responding to GET /1');
    },
    edit: function(req, res) {
        res.send('responding to GET /1/edit');
    },
    update: function(req, res) {
        res.send('responding to (PUT|PATCH) /1');
    },
    destroy: function(req, res) {
        res.send('responding to DELETE /1');
    }
}

app.use(resource('/', controller));

app.run();

Subdomain Routing

Along with resource routing, Kratos also ships with easy to use subdomain routing. The following utilizes both subdomain and resource routing to allow you to have a collection of users with a sub collection of their posts all tied to api.localhost.

var app = require('kratos');
var subdomain = require('kratos').Subdomain();
var resource = require('kratos').Resource();

app.use(subdomain('api.localhost', function(router) {
    router.use(resource('users', usersController));
    router.use(resource('users.posts', postsController));
}));

app.run();

The following routes are registered for the app.

GET api.localhost/users - show all users
POST api.localhost/users - create a user
GET api.localhost/users/1 - show user #1
PUT/PATCH api.localhost/users/1 - update user #1
DELETE api.localhost/users/1 - destroy user #1
GET api.localhost/users/1/posts - show all posts for user #1
POST api.localhost/users/1/posts - create a post for user #1
GET api.localhost/users/1/posts/1 - show post #1 for user #1
PUT/PATCH api.localhost/users/1/posts/1 - update post #1 for user #1
DELETE api.localhost/users/1/posts/1 - destroy post #1 for user #1

Testing

$ npm test

Credits

Keywords

FAQs

Package last updated on 28 Jul 2015

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