Coder Social home page Coder Social logo

hugodf / express-postgres-starter Goto Github PK

View Code? Open in Web Editor NEW
152.0 6.0 58.0 1.13 MB

A starter project for Node.js with Express and Postgres running on Docker Compose

Home Page: https://codewithhugo.com/node-postgres-express-docker-compose/

License: MIT License

Dockerfile 1.58% JavaScript 98.42%
nodejs express postgresql docker docker-compose

express-postgres-starter's Introduction

Express Postgres Starter

A starter project for Node.js with Express and Postgres

Setup

Pre-requisites:

  • Docker for Desktop

Run docker-compose up in the root of the project.

It will bring up Postgres and the Express application server in development mode.

It binds the application server to localhost:3000, this can be re-mapped this by changing the first 3000 in 3000:3000 of ./docker-compose.yaml).

Postgres is exposed on port 35432. The connection string is postgres://user:pass@localhost:35432/db (username, password and database name are defined in ./docker-compose.yaml).

You can connect to Postgres using the psql client:

psql postgres://user:pass@localhost:35432/db

The default Docker CMD is npm start, ./docker-compose.yaml overrides this to npm run dev which runs the application using nodemon (auto-restart on file change).

Express API setup

The Express API is located in ./src/api.

Applications routes for resources are defined in ./src/api/index.js.

Global concerns like security, cookie parsing, body parsing and request logging are handled in ./server.js.

This application loosely follows the Presentation Domain Data Layering:

  • Presentation is dealt with in the ./src/api folder
  • Domain is dealt with in the ./src/modules folder. It's currently non-existent since we've only got generic user and session resources.
  • Data is dealt with in the ./src/persistence folder

Database setup + management

npm run migrate up will run the migrations.

npm run migrate down will roll back the migrations.

npm run migrate:create <migration-name> will create a new migration file in ./src/migrations.

To run the migrations inside of docker-compose. Which will run a bash instance inside the app container.

docker-compose run app bash

Followed by:

npm run migrate up

Session/Authentication management

Session management is done through a custom sessions table, /api/session endpoints (see ./src/api/session.js) and leveraging client-sessions.

express-postgres-starter's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar hugodf avatar yanntoque avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

express-postgres-starter's Issues

The app doesn't return anything

I don't know if there is a bug with the app itself or the routes, the app doesn't returns anything apart from the default page, please take a look at the screenshot below.

image

The docker-compose up works fine, so does the app's default index page displaying "OK" only, however the api/* routes doesn't!

Thanks

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.