Hadron's purpose is to facilitate the building of Node.js applications:
Your application is built independently from other frameworks (Express, Koa). Hadron creates a layer between HTTP requests and your app written in plain Javascript.
Hadron abstracts away underlying request and response objects, providing simple data structures as input/output of your routes' handlers, making them simple to test and easy to deal with.
The dependency injection pattern enables you to easily change interface implementation. Hadron gives us the power to create SOLID applications.
Containers as a dependency management solution provides a convenient way to access all dependencies in functions.
The modular structure enables you to add/remove packages or create your own extensions. Hadron provides a complete solution for request processing using separate packages.
Current packages:
Built with TypeScript, but it's primary target is JavaScript apps. Hadron’s API embraces current ECMAScript standards, with the cherry of good IDE support via codebase types declarations on top.
To read more about hadron check out our article: How to use Hadron?
Install Node.js. We recommend using the latest version, installation details on nodejs.org
Install following modules from npm:
npm install @brainhubeu/hadron-core @brainhubeu/hadron-express express --save
Let's start with a simple Hello World app. It will give you a quick grasp of the framework.
const hadron = require('@brainhubeu/hadron-core').default;
const express = require('express');
const port = 8080;
const expressApp = express();
const config = {
routes: {
helloWorldRoute: {
path: '/',
callback: () => 'Hello world!',
methods: ['get'],
},
},
};
hadron(expressApp, [require('@brainhubeu/hadron-express')], config).then(() => {
expressApp.listen(port, () =>
console.log(`Listening on http://localhost:${port}`),
);
});
Hadron documentation can be found at http://hadron.pro
We recommend using latest version of node. If you want to use older versions you may need to add babel-polyfill to use some features.
git clone git@github.com:brainhubeu/hadron.git
cd brainhub-framework-app
npm install
npm run dev
npm start
npm run test
# or
PORT=8181 npm run test
Run unit tests for each package:
npm run test:unit
Run unit tests for a single package:
npm run test:package <package name>
PORT=8181 npm run test:e2e
It will run test.sh
script which in turn, will run app, wait for it to start listening and run npm run test:cucumber
command.
You need to provide the script with valid PORT or default (8080) will be used.
npm run lint # to just show linter errors and warnings
npm run lint:fix # to fix the errors and show what's left
Note! Because we're using "noImplicitAny": true
, we are required to have a .d.ts
file for every library we use. While we could set noImplicitAny
to false
to silence errors about missing .d.ts
files, it is a best practice to have a .d.ts
file for every library.
.d.ts
file via @types
. If it succeeds, you are done. If not, continue to next step..d.ts
file with dts-gen. If it succeeds, you are done. If not, continue to next step.<some-library>.d.ts
in types
folder.declare module '<some-library>';
.d.ts
file by following this guide on authoring .d.ts
files or continue with no types.npm i
on all packages, and compile them, just run lerna bootstrap
exec
command.
F.e. to compile all packages, you can run lerna exec tsc
node_modules
in packages, run lerna clean
node_modules
AND dist
directories, run npm run clean
lerna add <source-package-name> --scope=<target-package-name1>, <target-package-name2>
lerna publish
To get more command, please visit this link.