In an effort to standardize the router creation process, here's a general outline on how you should define your routes
GET /api /v2 /frogs /80085
Verb:_______| | | | |
#!/usr/bin/env node | |
const util = require('util'); | |
const exec = util.promisify(require('child_process').exec); | |
const fs = require('fs/promises'); | |
(async () => { | |
try { | |
const metaPath = `${process.cwd()}/.meta`; | |
const buffer = await fs.readFile(metaPath, {encoding: 'utf8'}); |
#!/usr/bin/env node | |
const argv = require('yargs/yargs')(process.argv.slice(2)) | |
.usage('Usage: $0 -p [str] ') | |
.example('$0 -p ./prod-changes/test.json5') | |
.alias('p', 'pattern') | |
.default('p', './prod-changes/config-data/**/*.json5') | |
.describe('p', 'Pattern (or path) of the json file(s) to validate') | |
.alias('x', 'exit-on-error') | |
.default('x', false) |
const bag = { | |
food: 'pizza', | |
drink: 'pepsi', | |
money: 20.01, | |
receipt: true, | |
}; | |
const { food, drink, ...whatsLeftInTheBag } = bag; | |
console.log(food); // 'pizza' | |
console.log(drink); // 'pepsi', |
// *** | |
// Best case for `return` | |
// *** | |
function isNumber(n) { | |
return (/^\d+$/).test(n); | |
} | |
// best solution: | |
// - creates on closure: function itself |
import config from './config'; // get a config somehow | |
import axios from 'axios'; | |
// https://github.com/axios/axios#config-defaults | |
export axios.create({ | |
baseURL: `${config.api.protocol}://${config.api.host}:${config.api.port}`, | |
auth: config.api.auth | |
}); |
/** | |
* Attempts to transmute a querystring order by value into a valid order by array | |
* | |
* Usually, the querystring value will look similar to: | |
* /sites/?orderBy=name,-id | |
* | |
* Which should be converted to: | |
* [ | |
* {field: 'name', order: 'asc'}, | |
* {field: 'id', order: 'desc'} |
// Each block is in a new file | |
// favorites-cache.js -- START | |
const ReditsClient = require('redis-client').Client; | |
// caching methods specific to Favorites (currently uses redis) | |
class FavoritesCache extends RedisClient { | |
constructor(conifg) { | |
super(config) | |
} |
let sId = 12345; // shootId | |
let pId = 83726; // performerId | |
let error; // error placeholder | |
// Example #1 | |
// default behavor | |
// error is returned if validation fails, `value` is actual validated value | |
let {error, value} = new Validator(sId).schema(require('constraints/shootId')).validate(); | |
// check for error | |
if (is.error(error)) { |
mkdir ~/.git_hooks
Stolen from: https://gist.github.com/bartoszmajsak/1396344#file-prepare-commit-msg-sh