Skip to content

cogsmith/xt1

Repository files navigation

🧰 XT: NodeJS Application Framework 🧰

Process Init, Runtime, Logging, Fastify, Nunjucks




XTDOOM


XT Secret Sauce: Ingredients BOM:

  • 🙊 [REDACTED]
  • 💦 99% perspiration
  • 🚧 constant evolution
  • 🍅 several tall glasses of V8
  • 🛠️ countless ecmatastic plumbing hacks
  • ⚔️ decades of battle-tested best practices
  • 🍰 near-excessive amounts of syntactic sugar
  • 🦖 ... and 1 velociraptor riding unicorn 🦄

Code Sandbox


Run Via Docker

mkdir /tmp/app ; cd /tmp/app
tee app.js <<EOF
    const XT = require('@cogsmith/xt').Init();
    const App = XT.App; const LOG = XT.LOG;
    App.Main = function () { LOG.INFO('XTNODE'); };
    App.Run();
EOF

eval `docker run --rm cogsmith/xtnode evalxtnode 2>/dev/null`
xtnode version

xtnode
xtnode --loglevel trace 
xtnode --loglevel trace --logjson 1

xtnodemon --loglevel trace

Docker Webserver

mkdir /tmp/app ; cd /tmp/app
tee app.js <<EOF
    const XT = require('@cogsmith/xt').Init();
    const App = XT.App; const LOG = XT.LOG;
    App.Routes = { ELSE: (req,rep) => { rep.send(Math.random()); } };
    App.Run();
EOF

eval `docker run --rm cogsmith/xtnode evalxtnode 2>/dev/null`
xtnode version

# Default Bind IP # XTNODE_BINDIP=127.0.0.1
xtnode

# Public Bind IP
XTNODE_BINDIP=0.0.0.0 ; xtnode

Docker App From Git Repo

eval `docker run --rm cogsmith/xtnode evalxtnode 2>/dev/null`
xtnodegit https://github.com/cogsmith/helloworld-xt

Minimal Example

const XT = require('@cogsmith/xt').Init();
const App = XT.App; const LOG = XT.LOG;    
App.Main = function () { LOG.INFO('HELLOWORLD'); };
App.Run();

Full Example

const XT = require('@cogsmith/xt').Init();
const App = XT.App; const LOG = XT.LOG;    

App.InitArgs = function () { 
    App.Argy = yargs(process.argv); 
}

App.InitInfo = function () { 
    App.SetInfo('App',function () { return 'EXAMPLE_FULL' });
}

App.InitData = function () { 
    App.MyDB = { FOO:123, BAR:Math.random() };
}

App.Init = function () {
}

App.InitDone = function () {
}

App.Main = function () {
}

App.Routes = { ELSEROOT: true };
App.Routes['/foo'] = (req,rep) => { rep.send('FOO'); };

App.Routes = {
    '/foo': (req,rep) => {
        let data = { action:'FOO', rand:Math.random() };
        rep.view('template',data);
    }
}

App.Run();