Skip to content

carlthomasiv/test-neon-local

 
 

Repository files navigation

Test Neon Local

Test repository for Neon Local

Getting started

  1. Rename .env.example to .env and add required values

  2. Install dependencies

npm install
  1. Start container
docker compose usp
  1. Visit http://localhost:4173/

src/db.js

The database connection is created using the Neon Serverless driver

import 'dotenv/config';

import { neon, neonConfig } from '@neondatabase/serverless';
neonConfig.fetchEndpoint = 'http://db:5432/sql';

export const sql = neon('postgres://neon:npg@db:5432/neondb');

docker-compose.yml

Contains necessary DRIVER value set to serverless

services:
  app:
    build: .
    ports:
      - '4173:4173'
    volumes:
      - .:/app
      - /app/node_modules
    depends_on:
      - db

  db:
    image: neondatabase/neon_local:latest
    ports:
      - '5432:5432'
    environment:
      NEON_API_KEY: ${NEON_API_KEY}
      NEON_PROJECT_ID: ${NEON_PROJECT_ID}
      DRIVER: serverless

.env

DATABASE_URL=postgres://neon:npg@db:5432/neondb
NEON_API_KEY=<api-key>
NEON_PROJECT_ID=<project-id>

Notes

There is an additional route for /book/:bookId, this is specific to the database. Routes can be added/amended in server-dev.js to suit the needs of the database. Simliar for src/function.js / getBookData, change as required.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 85.5%
  • Dockerfile 7.4%
  • HTML 7.1%