Skip to content

codedbychavez/express-postgresql-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express + PostgreSQL + Basic Auth

Welcome to a demo of Express + PostSQL + Basic Auth.

Getting started

  1. Add your PostgreSQL database configurations to modules/db/dbconfig.json.

  2. Run the app using:

npm run dev
  1. Check if the app connected successfully to the database. module/db/index.js logs the status of the database connection:
const pgPromise = require('pg-promise');
const dbConfig = require('./dbconfig.json');
const { Users } = require('./repos');

const initOptions = {
  extend(obj, dc) {
    obj.users = new Users(obj, pgp);
  }
}

// Initializing the library;
const pgp = pgPromise(initOptions);

// Creating the database instance;
const db = pgp(dbConfig);

// Test connection
db.one('SELECT NOW()')
  .then(result => {
    console.log('Connection successful:', result);
  })
  .catch(error => {
    console.error('Connection failed:', error.message || error);
  });

module.exports = {db};

API Endpoints

POST auth/signup

http://localhost:3000/auth/signup
// Request Body
{
  "username": "joe",
  "password": "password"
}

POST auth/login

// Request Body
{
  "username": "joe",
  "password": "password"
}

POST auth/logout

// Request Body

Helpful Resources

  • PostgreSQL Documentation: The official docs for PostgreSQL, the powerful open-source relational database.

  • pg-promise: A PostgreSQL client library for Node.js with a clean promise-based interface. Great for use with Express.

  • Passport.js: User Authentication.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published