Skip to content

Sample backend that saves product inventory listings in a Postgres database.

Notifications You must be signed in to change notification settings

humanitec-tutorials/sample-service

This branch is 3 commits ahead of, 1 commit behind corporate-org/product-be:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4eb0b76 · Apr 24, 2023

History

25 Commits
Mar 9, 2021
Mar 9, 2021
Nov 21, 2019
Oct 7, 2020
Nov 21, 2019
Nov 21, 2019
Jun 9, 2020
Mar 9, 2021
Nov 21, 2019
Apr 14, 2023
Mar 9, 2021
Nov 21, 2019
Apr 24, 2023
Mar 9, 2021
Apr 24, 2023
Apr 24, 2023
Mar 9, 2021

Repository files navigation

Demo sample backend

Overview

This is a simple Node.js backend app that creates and stores hypothetical product listings. Together with sample-app, its purpose is to demonstrate how to deploy a simple app on the Humanitec internal developer platform.

The app exposes an API on /products that allows you to create and list product items. Products are stored in a single table in a Postgres database.

Diagram: Architecture of the Humanitec demo app

Configuration

You can configure the app's database connection using these environmental variables:

Variable Description
CONNECTION_STRING The connection string for the PostgreSQL database in URL form

Running with docker-compose

The whole system can be run locally using docker-compose. This will run the product-be server and expose it on localhost:8080 and initialize a PostgreSQL database which can be accessed on localhost:5432. The admin password to the database is pgsqlDev01.

Run the following commands in the root of the repository:

$ docker-compose build
$ docker-compose up

Testing

Tests can be run with:

$ npm run test

Running locally

When running locally, you must have a PostgreSQL server up and running with a database created and with a PostgreSQL ROLE that has LOGIN rights.

After that, the server can be run with the following command:

$ CONNECTION_STRING="postgresql://product_robot:pr0dr0b0t@productdb:5432/product" \
  node bin/www

Now the database server is running on localhost:5432 with a database called product created by a user called product_robot with password pr0dr0b0t.

About

Sample backend that saves product inventory listings in a Postgres database.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 90.1%
  • Dockerfile 5.3%
  • Shell 4.6%