/fullstack-dev-scripts

A collection of scripts/snippets/cheat sheets I use during full stack development.

Fullstack Dev Scripts

A collection of scripts/snippets/etc I use during full stack development.

(I still use tldr pages as a cheat sheet for specific tooling examples. This repo is intended to contain scripts to achieve certain goals, and not as a generic reference for any particular toolset.)

Table of contents

npm/yarn package managment

list all top level JS dependencies

jq -r '.dependencies , .devDependencies | to_entries | .[] | .key' package.json | tr '\n' ' '

With versions:

jq -r '.dependencies | to_entries[] | .key as $k | .value as $v | "\($k)@\($v)"' package.json | tr '\n' ' '

find all linked packages

find node_modules -maxdepth 1 -type l -ls

JavaScript

Debugging

See: https://nodejs.org/api/debugger.html#debugger

breakOnException in particular is useful for debugging programs that gobble up stack traces

node inspect foo.js

Jest Tests

NODE_INSPECT_RESUME_ON_START=1 node inspect node_modules/.bin/jest --runInBand --coverage false /path/to/test.js

CLI Script

#!/usr/bin/env node

/**
 * @file Tool to do stuff
 *
 * Usage:
 *
 *   $ ./path/to/script <foo> <bar>
 */

async function main({ foo, bar }) {
    // do stuff
}

if (!process.env.NODE_ENV && require.main === module) {
    const [ , , foo, bar] = process.argv;
    
    main({ foo, bar }).catch(e => {
        console.error('\n======= Error caught in ./path/to/my/script =======');
        console.error(e);
        process.exit(1);
    });
}

Bash

killing all processes related to X

This is usually a super bad idea. Probably don't run this, unless you're feeling super lazy.

ps fux | grep my_service_here | tr -s ' ' | cut -d' ' -f2 | xargs kill

change the value of a constant in a directory

find /path/to/directory -type f -name "*.yaml" | xargs -I{} sed -i -e 's/mem: 2800/mem: 4096/g' {}

tree (with ignored directories)

tree -a -I 'node_modules|\.git'

bash script

#!/bin/bash
set -euo pipefail

# https://stackoverflow.com/a/246128/4396258
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT="${DIR}/.."

if [ "$#" -ne 1 ]
then
    echo '/path/to/script <foo>'
    exit 1;
fi

FOO="$1"
echo $FOO

Docker

run a hello world docker container (with cleanup)

docker run -it --rm ubuntu bash

build & run a container

docker build -t myapp1 .
docker run -it --rm --name app-instance myapp1