Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 64 lines (49 sloc) 1.27 KB
#!/usr/bin/env node
'use strict';
Today I Learned command-line app
const FactStore = require('./lib/factStore')
// Connection URL format:
// const url = 'mongodb://$[username]:$[password]@$[hostlist]/$[database]?authSource=$[authSource]';
// see
const dbUrl = process.env.MONGODB_URI || 'mongodb://localhost:27017';
const store = new FactStore(dbUrl);
async function start() {
// the first two args are full paths to the executable files,
// so ignore them
let params = process.argv.slice(2);
// the first real arg is the command
let command = params.shift();
if (command === 'help' || !command) {
else if (command === 'add') {
let text = params.join(' ').trim();
await store.addFact(text);
else if (command === 'list') {
await store.printAll();
else {
// The DB connection is still open, so we must explicitly exit
// display help and exit
function help() {
console.log(`Today I Learned
Run locally with:
node ./til.js
til add "something cool i learned today"
adds an entry to your TIL DB
til list
shows all entries, day by day
til help
shows this message
You can’t perform that action at this time.