1.2.763 • Published 6 years ago

agentstack v1.2.763

Weekly downloads
226
License
-
Repository
-
Last release
6 years ago

AgentStack for es6/typescript

Coverage Status

What is this?

  • Application Stack for Enterprise Applications

What is this actually???

  • Read configuration from conf/settings.yaml
  • Merge configuration from conf/${NODE_ENV}.yaml, conf/${NODE_ENV}.local.yaml and environment variables. (if have)
  • Merge configuration from data/settings.json (only when DATA_DIR was defined )
  • Print merged configuration on application start
  • Do not print sensitive configuration name with _KEY, _PASSWORD, _SECRET or _TOKEN postfix
  • Auto create missing dir if the configuration name ends with _DIR. (e.g. LOG_DIR folder)
  • Configuration with _DIR or _FILE will resolve to absolute path automatically
  • Provide a app.settings object for application to access the final configuration
  • Provide a app.logger object for application to use, available transporters: Console, File or Webhook
  • Provide nested error object Exception which will concat all the stacktrace for nested errors
  • When transporter itself got errors. It will automatically fallback to another available transporter
  • Trap linux signals SIGHUP, SIGINT, SIGQUIT, SIGTERM
  • Log nodejs process events uncaughtException
  • Provide universal application event beforeExit, exiting, exit
  • The original log called on failed transporter will logged using fallback logger
  • Add routing utils: router, route, param, middleware
  • Add container registry utils: router, route, param, middleware

Why doing this?

  • Because the things above is required for most enterprise applications. It should be shared across projects.
  • It's very important. But it's not as important as application logic. It can save your time to bootstrap a new project.
  • The same structure will make DevOps happy when doing deployment/monitoring on many projects. It should be standardized.
  • Together with Agent Framework; it can be automatically inject into other classes when required. It should be easy to use.

Installation

npm install agentstack --save

OR

yarn add agentstack

Show me the code

// TypeScript 2.2+
import { Application } from 'agentstack';

// Node 6+
var Application = require('agentstack').Application;


const app = new Application();

// enable config, logger support
app.init(); // default, same with `app.init({ confDir: 'conf', root: process.cwd() })`
// or
app.init({ confDir: 'settings' }); // if your configuration folder is not 'conf' 
// or
app.init({ confDir: 'settings', root: '/usr/share/myapp' }); // if your root folder is not current working folder 

console.log(app.settings);
app.logger.info('Hi, I am agent stack'); // the log will be automatically save in `LOG_DIR` folder 

or if you prefer using factory function instead of 'new'

// ES6 or TypeScript
import { CreateApplication } from 'agentstack';

// ES5
var CreateApplication = require('agentstack').CreateApplication;

var app = CreateApplication();
// or
var app = CreateApplication({ confDir: 'settings' });
// or
var app = CreateApplication({ confDir: 'settings', root: '/usr/share/myapp' });

console.log(app.settings);
app.logger.info('Hi, I am agent stack'); // the log will be automatically save in `LOG_DIR` folder in JSON format

Others

How do I rotate log files?

Consider we output our logs to /usr/share/myapp/logs/agent.log

We would rotate our log files with logrotate, by adding the following to /etc/logrotate.d/myapp:

/usr/share/myapp/logs/agent.log {
       su root
       daily
       rotate 7
       delaycompress
       compress
       notifempty
       missingok
       copytruncate
}
1.2.763

6 years ago

1.2.762

6 years ago

1.2.761

6 years ago

1.2.760

6 years ago

1.2.758

6 years ago

1.2.757

6 years ago

1.2.756

6 years ago

1.2.755

6 years ago

1.2.753

6 years ago

1.2.752

6 years ago

1.2.750

6 years ago

1.2.720

6 years ago

1.2.710

6 years ago

1.2.701

6 years ago

1.2.700

6 years ago

1.2.640

6 years ago

1.2.634

6 years ago

1.2.632

6 years ago

1.2.631

6 years ago

1.2.630

6 years ago

1.2.622

6 years ago

1.2.621

6 years ago

1.2.620

6 years ago

1.2.619

6 years ago

1.2.618

6 years ago

1.2.617

6 years ago

1.2.616

6 years ago

1.2.615

6 years ago

1.2.614

6 years ago

1.2.612

6 years ago

1.2.610

6 years ago

1.2.600

6 years ago

1.2.522

6 years ago

1.2.520

6 years ago

1.2.512

6 years ago

1.2.511

6 years ago

1.2.510

6 years ago

1.2.506

6 years ago

1.2.505

6 years ago

1.2.504

6 years ago

1.2.503

6 years ago

1.2.502

6 years ago

1.2.501

6 years ago

1.2.500

6 years ago

1.2.400

6 years ago

1.2.301

6 years ago

1.2.300

6 years ago

1.2.32

6 years ago

1.2.31

6 years ago

1.2.30

6 years ago

1.2.28

6 years ago

1.2.27

6 years ago

1.2.26

6 years ago

1.2.25

6 years ago

1.2.24

6 years ago

1.2.23

6 years ago

1.2.22

6 years ago

1.2.21

6 years ago

1.2.20

6 years ago

1.2.16

6 years ago

1.2.15

6 years ago

1.2.14

6 years ago

1.2.12

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.0

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.8

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.9.20

6 years ago

0.9.17

6 years ago

0.9.16

6 years ago

0.9.15

6 years ago

0.9.12

6 years ago

0.9.11

6 years ago

0.9.10

6 years ago

0.9.9

6 years ago

0.9.8

6 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.5.40

6 years ago

0.5.15

7 years ago

0.5.12

7 years ago

0.5.10

7 years ago

0.5.8

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.4.2

7 years ago

0.3.2

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago