Skip to content

This application subscribes to the PubNub Market Orders Stream via Node.js client and stores the market trades in the YugabyteDB database.

License

Notifications You must be signed in to change notification settings

YugabyteDB-Samples/market-orders-app-nodejs

Repository files navigation

Market Orders Steaming to YugabyteDB on Node.js

This application subscribes to the PubNub Market Orders Stream via Node.js client and stores the market trades in YugabyteDB.

Check this blog post for a quick app overview.

Run using YugabyteDB Managed

  1. Sign up for YugabyteDB Managed and create a free cluster. Additionally, follow this guide to download your cluster CA certificate and set up your cluster IP allow list.

  2. Run the following to install dependencies (first time only):

cd market-order-app-nodejs
npm install
  1. Configure your DATABASE_URL environment variable in the .env file:
# format
DATABASE_URL="postgresql://[DB_USERNAME]:[DB_PASSWORD]@[DB_HOST]:5433/
yugabyte?statement_cache_size=0&sslmode=require"

# example
DATABASE_URL="postgresql://admin:qwerty12345@us-west-2.foobarbaz.aws.ybdb.io:5433/
yugabyte?statement_cache_size=0&sslmode=require"
  1. Run the following to initialize database:
# create tables and relations
npx prisma db execute --file prisma/db_schema.sql --schema prisma/schema.prisma

# introspect Postgres schema to create Prisma schema
npx prisma db pull

# manually add the materialized view to the schema.prisma file 
# views are not introspected by Prisma
model top_buyers_view {
  first_name String
  last_name String
  total_portfolio_value Int

  @@unique([first_name, last_name, total_portfolio_value])
}

# generate prisma client
npx prisma generate

# seed users in database
npx prisma db seed

  1. Run the sample application:
cd market-orders-client
npm install
npm run build
cd ..
npm start
open localhost:8000
  1. Development (optional)
# This will automatically open browser window and proxy requests to the server
# npm run start-dev

Run locally

  1. Install YugabyteDB.

  2. Run the following to install dependencies (first time only):

cd market-order-app-nodejs
npm install
  1. Configure your DATABASE_URL environment variable in the .env file:
# format
DATABASE_URL="postgresql://[DB_USERNAME]:[DB_PASSWORD]@[DB_HOST]:5433/yugabyte?statement_cache_size=0"

# example
DATABASE_URL="postgresql://yugabyte:yugabyte@127.0.0.1:5433/yugabyte?statement_cache_size=0"
  1. Run the following to initialize database:
# create tables and relations
npx prisma db execute --file prisma/db_schema.sql --schema prisma/schema.prisma

# introspect Postgres schema to create Prisma schema
npx prisma db pull

# manually add the materialized view to the schema.prisma file 
# views are not introspected by Prisma
model top_buyers_view {
  first_name String
  last_name String
  total_portfolio_value Int

  @@unique([first_name, last_name, total_portfolio_value])
}

# generate prisma client
npx prisma generate

# seed users in database
npx prisma db seed

  1. Run the sample application:
cd market-orders-client
npm install
npm run build
cd ..
npm start
open localhost:8000
  1. Development (optional)
# This will automatically open browser window and proxy requests to the server
# npm run start-dev

About

This application subscribes to the PubNub Market Orders Stream via Node.js client and stores the market trades in the YugabyteDB database.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published