Giter Club home page Giter Club logo

template--user-system-express-postgres's Introduction

Project Info

VS Code Extensions

  • Better Comments
    • Allows comment colors:
      • // * <-- Green Comments. For calling out conditional flow

A Template User System: Social Auth + Default Auth.

The project will initally be just a user mgmt template, useful for building apps in general.

Swagger stuff:

https://dev.to/przpiw/document-express-api-with-swagger-51in


KnexJS stuff

knex migrate:up knex migrate:make migration_one knex seed:make seed_one_clear_db knex seed:make seed_two_initialize_data knex seed:run --specific=seed_two_initialize_data.js

Knex can be a little funky... Or maybe I just need to experiment with it a little more. For local dev on laptop, connect via: connection: process.env.DB_CONNECTION_LOCAL_LAPTOP_DEV, "DB_CONNECTION_LOCAL_LAPTOP_DEV": "postgres://root:root@localhost:5432/root", (previously had: "DB_CONNECTION": "postgres://localhost:5432/root@root",)

but strangely had this issue from postgres container log:
2023-08-23 22:03:30.642 UTC [39] FATAL:  password authentication failed for user "patrickmeaney"

but the new way works.

vs on remote ubuntu server, this works: connection: { host: process.env.DEV_DOCKER_POSTGRES_CONTAINER_NAME, database: process.env.DEV_POSTGRES_USER, user: process.env.DEV_POSTGRES_PASSWORD, password: process.env.DEV_POSTGRES_DATABASE_NAME, }, "DEV_DOCKER_POSTGRES_CONTAINER_NAME": "postgres-proj-postgres-1", "DEV_POSTGRES_USER": "root", "DEV_POSTGRES_PASSWORD": "root", "DEV_POSTGRES_DATABASE_NAME": "root",

Docker stuff

docker compose -f docker-compose-local.yml up --build

On local dev laptop (docker-compose-local.yml), I use slightly different settings-- basically, I only need to connect the NodeJS & Postgres containers to the same network. And, the image is built locally. Whereas, in the docker-compose-remote.yml, we pull the published image, and connect the NodeJS app container to the nginx container's network (which the remote postgres container is also connected to)

  • On laptop, use: docker compose -f docker-compose-local.yml up When you install something new though, you'll need to tell docker to rebuild with --build as shown here: docker compose -f docker-compose-local.yml up --build

  • On remote, use: docker compose -f docker-compose-remote.yml up

  • To publish to github docker registry automatically, commit to the branch specified at ./.github/workflow/build_publish_pull.yaml

Or, if you want to publish manually:

export CR_PAT=githubToken
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
docker build -t ghcr.io/pmeaney/express-knex-proj . 
docker push ghcr.io/pmeaney/express-knex-proj:latest

Source of Docker Compose template for connecting NodeJS with Postgres (& PGAdmin): https://github.com/alexeagleson/docker-node-postgres-template

export CR_PAT=githubToken
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
docker build -t ghcr.io/USERNAME/PACKAGENAME . 
docker push ghcr.io/USERNAME/PACKAGENAME:latest

Architecture sections

// simple argon2 example from https://github.com/ranisalt/node-argon2#readme
// run "node" then paste this:
const argon2 = require('argon2');
const hash = await argon2.hash("password");
console.log('hash is: ', hash;)
await argon2.verify(hash, "password")
// nodejs example in CLI REPL
 node        
Welcome to Node.js v18.16.1.
Type ".help" for more information.
> const argon2 = require('argon2');
undefined
> const hash = await argon2.hash("password");
undefined
> hash;
'$argon2id$v=19$m=65536,t=3,p=4$8nDd6IlGzAV+xkYCMuZYGQ$yjxQvSagvZrbs0yy9QAzzoalnQ97tg240VsEv8ZbwyE'
> await argon2.verify(hash, "password")
true

Since the Argon2 library generates a salt for us (https://github.com/ranisalt/node-argon2/wiki/Options#salt) Do we need to still extract its salt and store it in the DB?

Well, as it turns out, Argon2's hash function output includes the salt within it already. So by storing the hash, since it already includes a salt value by default (default is 16 chars), the salt is stored as well. More info here in the "Storing Passwords" section: https://www.alexedwards.net/blog/how-to-hash-and-verify-passwords-with-argon2-in-go

template--user-system-express-postgres's People

Contributors

pmeaney avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.