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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dbf-mssql

v0.1.0

Published

DBF MSSQL: .env-driven MSSQL client focused on stored procedures

Readme

DBF MSSQL (dbf-mssql)

Server-side MSSQL helpers for Node.js:

  • Load connection settings from .env / process.env
  • Create and reuse a connection pool
  • Execute stored procedures (and raw queries if needed)

This package is intentionally self-contained: it ships with mssql and dotenv so consumers do not need to install extra dependencies.


Installation

npm install dbf-mssql

dbf-mssql is Node.js-only (do not bundle it into the browser).


Environment variables

By default, dbf-mssql reads variables with the DBF_MSSQL_ prefix.

Required:

  • DBF_MSSQL_SERVER
  • DBF_MSSQL_DATABASE
  • DBF_MSSQL_USER
  • DBF_MSSQL_PASSWORD

Optional:

  • DBF_MSSQL_PORT
  • DBF_MSSQL_ENCRYPT (default: true)
  • DBF_MSSQL_TRUST_SERVER_CERTIFICATE (default: false)
  • DBF_MSSQL_REQUEST_TIMEOUT_MS
  • DBF_MSSQL_CONNECT_TIMEOUT_MS
  • DBF_MSSQL_POOL_MAX
  • DBF_MSSQL_POOL_MIN
  • DBF_MSSQL_POOL_IDLE_TIMEOUT_MS

Example .env:

DBF_MSSQL_SERVER=localhost
DBF_MSSQL_DATABASE=MyDb
DBF_MSSQL_USER=sa
DBF_MSSQL_PASSWORD=YourStrong(!)Password

# optional
DBF_MSSQL_PORT=1433
DBF_MSSQL_ENCRYPT=true
DBF_MSSQL_TRUST_SERVER_CERTIFICATE=true
DBF_MSSQL_REQUEST_TIMEOUT_MS=30000
DBF_MSSQL_CONNECT_TIMEOUT_MS=15000
DBF_MSSQL_POOL_MAX=10
DBF_MSSQL_POOL_MIN=0
DBF_MSSQL_POOL_IDLE_TIMEOUT_MS=30000

Custom prefix:

createMssqlClientFromEnv({ prefix: "MYAPP_MSSQL_" })


Quick start: execute a stored procedure (one-shot)

import { execProcFromEnv, param, sql } from "dbf-mssql";

const result = await execProcFromEnv("dbo.MyProc", {
  UserId: 123,
  Name: param("Ada", sql.NVarChar(50)),
});

console.log(result.recordset);
console.log(result.output);
console.log(result.returnValue);

execProcFromEnv(...) creates a client, executes the proc, then closes the pool.


Reuse the pool with a client

import { createMssqlClientFromEnv } from "dbf-mssql";

const client = createMssqlClientFromEnv();

const r1 = await client.execProc("dbo.MyProc", { UserId: 123 });
const r2 = await client.query("select 1 as ok");

await client.close();

Typed input params

If you need to force a SQL type, use param(value, type) and sql.* types:

import { execProcFromEnv, param, sql } from "dbf-mssql";

await execProcFromEnv("dbo.SaveUser", {
  Id: param(123, sql.Int),
  Name: param("Ada", sql.NVarChar(50)),
  Bio: param("...", sql.NVarChar(sql.MAX)),
});

API

  • mssqlConfigFromEnv(options?): load + validate config from env (optionally calls dotenv.config())
  • createMssqlClientFromEnv(envOptions?, clientOptions?): create a DbfMssqlClient from env
  • execProcFromEnv(procName, inputs?, outputs?, envOptions?): execute proc and close pool
  • DbfMssqlClient: connect(), close(), query(), execProc()
  • param(value, type?): build a typed input param
  • sql: normalized mssql module exports (works in ESM and CJS)

Additional helpers on DbfMssqlClient:

  • ping() – simple select 1 health check
  • withTransaction(fn) – runs a function inside a SQL transaction (auto commit/rollback)

Security / architecture note

Do not connect to MSSQL from the browser. Use:

  • Frontend → calls your backend API
  • Backend (Node.js) → uses dbf-mssql to run procs/queries

Transactions (example)

import { createMssqlClientFromEnv } from "dbf-mssql";

const client = createMssqlClientFromEnv();

await client.withTransaction(async (tx) => {
  const request = tx.request();
  await request.query("update Users set active = 1 where id = 42");
  await request.query("insert into Logs(message) values('user activated')");
});

Optional logging hook

import { createMssqlClientFromEnv } from "dbf-mssql";

const client = createMssqlClientFromEnv({}, {
  log: (event) => {
    if (event.type.endsWith(":error")) {
      console.error(event);
    }
  },
});