Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save artificialarea/29445253c7d84264a98ca790c80d9c08 to your computer and use it in GitHub Desktop.
Save artificialarea/29445253c7d84264a98ca790c80d9c08 to your computer and use it in GitHub Desktop.
Notes on learning and using command line interfaces when developing express/prostgres back end software.

Compare GUI vs CLI

  • CLI - good for
    • low bandwidth environments (talking to cloud servers)
    • very fast interactions for users that already know which command to use
    • can use scripts and the alias command to create powerful custom commands
  • GUI - good for
    • exploring functionality & learning
    • Seeing structure and organization - how things relate to each other

How do I learn a CLI? (Unix/Linux/Mac)

  • Stay local - exhaust your local resources before googling
    • Built-in help
      • pg_ctl --help
      • psql --help
      • psql \q command
    • man pages (Try these in your shell)
      • man man
      • man zsh (or man bash)
      • man pg_ctl
      • man psql
  • Practice reading text that is hard to read
    • You may have to force yourself to keep reading every line when you feel lost.
    • Skim & scan to get an overview, then read for detail
    • This skill also helps with reading error messages
    • This skill also helps with reading code
  • Have a clear idea of what the CLI is supposed to do. (See if you can say a simple statement like "I want to list databases")
  • Keep a notebook in a text file with a selection of command strings and what they do
  • Your goal is not just to get a quick answer. It's to build your brain muscles to work in this text-heavy, jargon-filled environment.

Essential skill - situational awareness: Where am I? Where should I be?

What command line environment am I in?

  • Powershell?
  • gitbash?
  • bash/zsh?
  • psql?
  • text pager?

What commands are expected?

Look at the prompt. Are you in zsh? psql? a text pager?

What folder am I in?

What's running on my machine right now?

Usually, there are several ways to do a thing

Which user interface should I use for the command to ...

  • ... create a user role? createuser or psql or dbeaver?
  • ... create a database? createdb or psql or dbeaver?
  • ... run a SQL script? psql or dbeaver?

Try them all before forming habits.

Startup checklist (Start & maintain your own!)

I tend to do something similar to this whenever I start working on express/postgres:

  • Reboot the machine (Really! Just do it. Every day at least.)
  • Log in to your development account (if your normal account is having trouble installing tools, create a fresh account on your laptop)
  • Launch a command line shell
  • In shell: Navigate to your project folder
  • In shell: Launch postgresql database server
  • Launch database client (psql or dbeaver) & verify server is running
  • In shell: Launch vscode (code .)
  • Pick a CLI - your shell or a vscode terminal - and stick with it
  • Run tests (npm test) or server (npm run dev) from that CLI and only that CLI

You should always have these tools available:

  1. postgresql database server
  2. CLI shell in project folder
  3. Database client (psql, dbeaver, or both)
  4. vscode
  5. Postman

Debugging checklist (Start & maintain your own!)

  • Is the postgresql server running? (pg_ctl status)
  • Is only one instance of node/express running? (ps)
  • Is my connection spec correct? (use dbeaver to test connection)
  • Am I in the right CLI? (look at the prompt characters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment