Run Total.js v5 without NPM installation
This sounds almost illegal, but it works: you can run the Total.js framework without installing it from NPM. Just pure Node.js, dynamic loading, and the full power of Total.js ready to go.
Just keep the standard Total.js directory structure - controllers, views, definitions and the usual suspects and everything will work like a charm. The framework will detect your app structure and run it exactly as expected.
Create index.js file:
require('https').get('https://cdn.totaljs.com/total5.js', function(res) {
let data = [];
res.on('data', chunk => data.push(chunk));
res.on('end', function() {
eval(Buffer.concat(data).toString('utf8'));
const options = {};
// options.ip = '127.0.0.1';
// options.port = parseInt(process.argv[2]);
// options.unixsocket = PATH.join(F.tmpdir, 'app_name.socket');
// options.unixsocket777 = true;
// options.config = { name: 'Total.js' };
// options.sleep = 3000;
// options.inspector = 9229;
// options.watch = ['private'];
// options.livereload = 'https://yourhostname';
// options.watcher = false; // disables watcher
// options.edit = 'wss://www.yourcodeinstance.com/?id=projectname'
options.release = process.argv.includes('--release');
// Service mode:
options.servicemode = process.argv.includes('--service') || process.argv.includes('--servicemode');
// options.servicemode = 'definitions,modules,config';
// Cluster:
// options.tz = 'utc';
// options.cluster = 'auto';
// options.limit = 10; // max 10. threads (works only with "auto" scaling)
Total.run(options);
});
});
And run it $ node index.js. That’s it. Boom - your Total.js app is running.
Single app file
Don’t want to create a full directory structure and prefer a single run script with everything inside? No problem. Check out the code below - one file, one command and your Total.js app is ready to roll.
Create index.js file:
require('https').get('https://cdn.totaljs.com/total5.js', function(res) {
let data = [];
res.on('data', chunk => data.push(chunk));
res.on('end', function() {
eval(Buffer.concat(data).toString('utf8'));
const options = {};
// options.ip = '127.0.0.1';
// options.port = parseInt(process.argv[2]);
// options.unixsocket = PATH.join(F.tmpdir, 'app_name.socket');
// options.unixsocket777 = true;
// options.config = { name: 'Total.js' };
Total.http(options);
// Your custom code:
ROUTE('GET /', $ => $.plain('Hello world!'));
});
});
And run it $ node index.js.