Skip to content

Command

import { Command } from 'commander';




const program = new Command();

program

.name('dentropys-obsidian-publisher')

.description('This project build a static website using mkdocs from your obsidian vault.')

.option('-i, --inpath <string>')

.option('-o, --outpath <string>')

.option('-oi, --offsetindex <int>')

.option('-mkdn, --mkfilesfoldername <string>')

program.parse(process.argv)

const options = program.opts()



console.log(options)

let pattern = ''

if ( !(Object.keys(options).includes("inpath")) ){

console.log("You failed to set input path '-i $FOLDER_PATH' for you markdown documents")

process.exit(1);

}

else {

pattern = options.inpath;

if (pattern.charAt(pattern.length - 1) != '/'){

pattern += '/'

}

pattern += '**/*.md'

}



let out_path = ''

if ( !(Object.keys(options).includes("outpath")) ){

console.log("You failed to set output path '-o $FOLDER_PATH' for you markdown documents")

process.exit(1);

}

else {

out_path = options.outpath

}



let offset_index = 0

if ( (Object.keys(options).includes("offsetindex")) ){

offset_index = options.offsetindex

}



let mkfiles_directory_name = 'markdown_files'

if ( (Object.keys(options).includes("mkfilesfoldername")) ){

mkfiles_directory_name = options.mkfilesfoldername

}



console.log(`pattern: ${pattern}`)

console.log(`out_path: ${out_path}`)

console.log(`offset_index: ${offset_index}`)

console.log(`mkfiles_directory_name: ${mkfiles_directory_name}`)

console.log

const util = require('util')

import util from 'util'

// alternative shortcut
console.log(util.inspect(myObject, false, null, true))

console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true}))

Stuff to Organize

Object stuff

File Stuff

wiki.software.List.docker

How To Build a Node.js Application with Docker | DigitalOcean

Usefil Packages

Problems Solved

Dependency Hell

Troubleshooting

  • For example code run from root directory.

To Learn

app.get('/test', jsonParser, function (req, res) {
console.log(req.body)
res.send("Test, yes that was a test")
});

app.post('/test', jsonParser, function (req, res) {
console.log(req.body)
res.send("Test, yes that was a test")
});
console.log(`${key}: ${value}`);
try {
    nonExistentFunction();
} catch (error) {
    console.error(error);
    // expected output: ReferenceError: nonExistentFunction is not defined
    // Note - error messages will vary depending on browser
}
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

Exec Commands

File System Commands

Module Error

,
{"type": "module" }

Exit Process

How to exit from a Node.js program

String Stuff

Array Stuff

Regex

  • [[https://stackoverflow.com/questions/1981349/regex-to-replace-multiple-spaces-with-a-single-space#comment1897704_1981349]]
  • RegExp - JavaScript | MDN

Read JSON File

Try Catch

Terminal Input

async function questionExample() { try { const answer = await question('What is you favorite food? '); console.log(Oh, so your favorite food is ${answer}); } catch (err) { console.error('Question rejected', err); } } questionExample(); ``` * Attempts that did not work with await * How do I prompt users for input from a command-line script? | Node.js * [[|[|[|[|) Module - GeeksforGeeks * javascript - Using readline in Node.js - Stack Overflow * How to read and write JSON files in Node.js * How to Readline - an example and the beginnings of the docs

TODO