npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wildsoft/express-pg-extension

v1.0.2

Published

Express middleware with PostgreSQL integration for Wildsoft

Downloads

198

Readme

Express PostgreSQL Extension

Express 애플리케이션에 PostgreSQL 기능을 쉽게 통합할 수 있는 미들웨어 패키지입니다.

특징

  • Express 앱과 PostgreSQL 통합
  • 필요한 테이블 자동 생성
  • REST API 엔드포인트 제공
  • 커스텀 라우트에서 PostgreSQL pool 접근 가능

설치

npm install express-pg-extension

사용법

const express = require('express');
const { Pool } = require('pg');
const { initialize } = require('express-pg-extension');

const app = express();
app.use(express.json());

// PostgreSQL 연결 설정
const pool = new Pool({
    user: 'your_user',
    host: 'localhost',
    database: 'your_database',
    password: 'your_password',
    port: 5432,
});

// 패키지 초기화
// 필요한 테이블이 없다면 자동으로 생성됩니다
initialize(app, pool);

// 이제 '/api/users' 엔드포인트가 자동으로 추가되었습니다
app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

데이터베이스 스키마

패키지는 다음과 같은 테이블을 자동으로 생성합니다:

users 테이블

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

제공되는 API 엔드포인트

GET /api/users

모든 사용자 목록을 조회합니다.

POST /api/users

새로운 사용자를 생성합니다.

요청 본문 예시:

{
    "name": "John Doe",
    "email": "[email protected]"
}

커스텀 라우트 추가

패키지를 사용하면서도 자체 라우트를 추가할 수 있습니다:

app.get('/custom', async (req, res) => {
    // req.pgPool을 통해 PostgreSQL pool에 접근 가능
    const result = await req.pgPool.query('SELECT * FROM custom_table');
    res.json(result.rows);
});