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
- How to Check for
NaN
in JavaScript - Mastering JS - node.js - Dockerfile build /bin/sh -c returned a non-zero code: 1 - Stack Overflow
- How to exit in Node.js - Stack Overflow
- node.js - Javascript - How to convert buffer to a string? - Stack Overflow
- node.js - NodeJS, Axios - post file from local server to another server - Stack Overflow
- form-data - npm
- Send a File With Axios in Node.js - Maxim Orlov
- node.js - How to unit test with a file upload in mocha - Stack Overflow
Object stuff
File Stuff
- https://stackoverflow.com/questions/3459476/how-to-append-to-a-file-in-node
- How to Append File in NodeJS - Fedingo
- How to read a file line by line using node.js ? - GeeksforGeeks
- node.js remove file - Stack Overflow
- node.js - Get all directories within directory nodejs - Stack Overflow
- How to check if a directory exists in Node.js
wiki.software.List.docker
How To Build a Node.js Application with Docker | DigitalOcean
Usefil Packages
Problems Solved
- node.js - NPM not found when using NVM - Stack Overflow
- node.js - Proxy with express.js - Stack Overflow
- node.js - BodyParser is deprecated - Stack Overflow
Dependency Hell
Troubleshooting
- For example code run from root directory.
To Learn
- Authentication
- Basic Authentication
- Bearer Token
- Oauth
- OpenID
- UnhandledPromiseRejectionWarning:
- nodemon
- Promises
- Useful Links From Troubleshooting
- Object](../.md)? l need to pause for a period of time - Stack Overflow? l need to pause for a period of time - Stack Overflow](dentropydaemon-wiki/Software/List/Javascript.md)? l need to pause for a period of time - Stack Overflow]]?%20l%20need%20to%20pause%20for%20a%20period%20of%20time%20-%20Stack%20Overflow)
- javascript - How to append to a file in Node? - Stack Overflow
- Object](../.md) within directory node-fs - Stack Overflow within directory node-fs - Stack Overflow](name,%20type,%20size) within directory node-fs - Stack Overflow]]%20within%20directory%20node-fs%20-%20Stack%20Overflow)
- javascript - How do you get a list of the names of all files present in a directory in Node.js? - Stack Overflow
- How to unset a JavaScript variable? - Stack Overflow
- Get Query Strings and Parameters in Express.js
- Serving Static Files with Node and Express.js
- My current HTML boilerplate - Manuel Matuzović
- passport.js WILL NOT RETURN YOUR PARSED JSON, use body-parser instead
- javascript - Load and execute external js file in node.js with access to local variables? - Stack Overflow
- javascript - In nodeJs is there a way to loop through an array without using array size? - Stack Overflow
- debugging - Check if object exists in JavaScript - Stack Overflow
- javascript - How to append something to an array? - Stack Overflow
- https://stackoverflow.com/questions/1981349/regex-to-replace-multiple-spaces-with-a-single-space, rather than '[[.md|Object]], rather than '[[.md|Object]], rather than '[Object]],%20rather%20than%20'%5C%5BObject%5C)
- javascript - What does => mean in node js - Stack Overflow
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")
});
- Getting the Request Body in Express - Mastering JS
- arrays - Nested forEach loops to add object to existing object javascript - Stack Overflow
- Send a JSON response using Express
- Array.prototype.length - JavaScript | MDN
- Express error handling
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
- Check Exists
- How to check if a directory exists in Node.js
Module Error
,
{"type": "module" }
Exit Process
How to exit from a Node.js program
String Stuff
- Template
- ES6 Template/String Literals in Node.js
- Substring
- How do you split a string into two array items in Javascript? - Stack Overflow
- [[|[|[|[|) function - GeeksforGeeks
Array Stuff
- Length
- JavaScript Array length Property
- Iterate
- Node.js forEach - Examples
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
- What is try-catch? | Node.js
- Error handling with async/await and promises, n² ways to shoot yourself in the foot | CatchJS
Terminal Input
- Readline | Node.js v16.10.0 Documentation ``` javascript const util = require('util'); const question = util.promisify(rl.question).bind(rl);
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
- How to Concatenate Strings in an Array using JavaScript - Mastering JS
- How to read and write JSON files in Node.js
- javascript - How to print object in Node JS - Stack Overflow
- How to Check if a Key Exists in JavaScript Object
- Optional Parameters in Javascript
- How to read and write JSON files in Node.js
- Zell Liew
- node.js - How to use await in a forEach loop in nodejs - Stack Overflow
- concat two list elements which are different in javascript Code Example
- MDN
- [[Delete Duplicates|[Delete Duplicates|[Delete Duplicates|[Delete Duplicates|Delete Duplicates)