Getting started with Thorin.js

In order to initialize a thorin.js project, the first thing you have to do is install the core module. Note that Thorin.js will only work with Node.js >= 4.x. If your application is still running on Node <= 0.12, it is time to upgrade.

npm install thorin@latest

Next, depending on the functionality you want to implement, you'd take a look at the existing plugins, stores and transports. Once you've decided on the list of components you want, install them in your project. In the use case bellow, we will use type as the component type and name as its name. Current component types are transport, store, plugin, library.

npm install thorin-{type}-{name} # eg: thorin-transport-http

Once you've installed your components, create your entry file (app.js) and load up all your components. It is recommended that the first time you add a new component to set it up, so that it can execute setup specific functionality. You do so by running your app with node app.js --setup={type}.{name}

You should now create your application's entry file, app.js and tell it which components to load and capture any other events that you wish to handle.

'use strict';
const thorin = require('thorin');
// Tell thorin to load and work with the required components
thorin
   .addTransport(require('thorin-transport-http'))
   .addStore(require('thorin-store-sql'));
if(thorin.env === 'development') {
   thorin.addPlugin(require('thorin-plugin-docs'));
}
// Once we've done so, boot up the application
thorin.run((err) => {
   if(err) {
      log.fatal(`Something bad happened: ${err.code}`, err);
      return process.exit(1);
   }
   log.info(`Application launched`);
});

By default, Thorin's core will automatically recursively require your application's app/actions and app/middleware folders. Other Thorin components will provide the auto-loading feature, depending on their structure dependencies (see below).

As a friendly reminder, we strongly recommend that before you start coding on your application, have an architectural overview for it and divide it into multiple specialized microservices, that will work with the discovery plugin for inter-communication. This will save you a lot of headaches down the line.

Default project structure

A regular Thorin app will have the following folder structure. Depending on which components you end up using, it will influence it. This is the structure we encourage you to use, to avoid any compatibility issues.

  • app/ - Your application's root folder
    • actions/ - Place all your app's actions here.
    • middleware/ - Place all your app's middleware and authorizations here.
    • models/ - When using the SQL store, place all your application's models here.
    • lib/ - Place all your application's library files here.
    • styles/ - When using the LESS or SASS css processor, place all your application styles here.
    • views/ - When using the render plugin, place all your view templates here.
    • emails/ - When using the email plugin, place all your email related templates here.
    • tasks/ - When using the tasks plugin, place all your task definitions here.
  • config/ - Folder to place any kind of configuration.
    • env/ - Place all your environment specific configuration here, as development.js or production.js
    • {entryFile}.js - The general configuration for your application's entry file. Defaults to app.js
  • public/ - If you use the HTTP transport, all your application's public assets go here,
  • docs/ - If you're using the docs generator plugin, it will generate your markdown documentation and place it here.
  • package.json - Your application's package file containing project dependencies and other.
  • .gitignore - Your git repository's git ignore file.
  • {entryFile}.js - The entry point for your application, defaults to app.js
Do you have a question or is something missing?

You can always create a new issue on GitHub or contact one of the core founders by chat.