1.2.763 • Published 7 years ago

agentstack v1.2.763

Weekly downloads
226
License
-
Repository
-
Last release
7 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

7 years ago

1.2.762

7 years ago

1.2.761

7 years ago

1.2.760

7 years ago

1.2.758

7 years ago

1.2.757

7 years ago

1.2.756

7 years ago

1.2.755

7 years ago

1.2.753

7 years ago

1.2.752

7 years ago

1.2.750

7 years ago

1.2.720

7 years ago

1.2.710

7 years ago

1.2.701

7 years ago

1.2.700

7 years ago

1.2.640

7 years ago

1.2.634

7 years ago

1.2.632

7 years ago

1.2.631

7 years ago

1.2.630

7 years ago

1.2.622

7 years ago

1.2.621

7 years ago

1.2.620

7 years ago

1.2.619

7 years ago

1.2.618

7 years ago

1.2.617

7 years ago

1.2.616

7 years ago

1.2.615

7 years ago

1.2.614

7 years ago

1.2.612

7 years ago

1.2.610

7 years ago

1.2.600

7 years ago

1.2.522

7 years ago

1.2.520

7 years ago

1.2.512

7 years ago

1.2.511

7 years ago

1.2.510

7 years ago

1.2.506

7 years ago

1.2.505

7 years ago

1.2.504

7 years ago

1.2.503

7 years ago

1.2.502

7 years ago

1.2.501

7 years ago

1.2.500

7 years ago

1.2.400

7 years ago

1.2.301

7 years ago

1.2.300

7 years ago

1.2.32

7 years ago

1.2.31

7 years ago

1.2.30

7 years ago

1.2.28

7 years ago

1.2.27

7 years ago

1.2.26

7 years ago

1.2.25

7 years ago

1.2.24

7 years ago

1.2.23

7 years ago

1.2.22

7 years ago

1.2.21

7 years ago

1.2.20

7 years ago

1.2.16

7 years ago

1.2.15

7 years ago

1.2.14

7 years ago

1.2.12

7 years ago

1.2.11

7 years ago

1.2.10

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.0

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.8

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.9.20

7 years ago

0.9.17

7 years ago

0.9.16

7 years ago

0.9.15

7 years ago

0.9.12

7 years ago

0.9.11

7 years ago

0.9.10

7 years ago

0.9.9

7 years ago

0.9.8

7 years ago

0.9.7

7 years ago

0.9.6

7 years ago

0.9.5

8 years ago

0.9.4

8 years ago

0.9.3

8 years ago

0.9.2

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.5.40

8 years ago

0.5.15

8 years ago

0.5.12

8 years ago

0.5.10

8 years ago

0.5.8

8 years ago

0.5.7

8 years ago

0.5.6

8 years ago

0.5.5

8 years ago

0.4.2

9 years ago

0.3.2

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago