Nanit NodeJS Async Cold Start Pre-conditions Sequencial Initializer/Finalizer

JS
S
JavaScript

Simple but efficient initialization mechanism for NodeJS projects. Initializer files are stored in a folder called "initializers" at the root of the project. https://www.npmjs.com/package/nanit Example: package.json initializers/mongo.js initializers/redis.js initializers/myRpc.js

1// index.js
2// ----------------------------------------------------------
3const nanit = require('nanit');
4// Initialization Middleware (via Nanit)
5nanit.initialize((err) => {
6    if (err) { throw err; }
7    // start your app
8});
9
10
11// ./initializers/mongo.js
12// ----------------------------------------------------------
13const mongoose = require('mongoose');
14const epa = require('epa').getEnvironment();
15
16// Configure Mongo DB Connection
17module.exports = function(next){
18	mongoose.connect(epa.get('mongodb'), (err) =>{
19		if(err) { return next(err); }
20		Logger.log(`====== Express Server Connected to Mongo ${epa.get('mongodb')}======`);
21		next();
22	});
23}
24

Created on 4/8/2018