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.
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.
You can always create a new issue on GitHub or contact one of the core founders by chat.