What is @tediousjs/connection-string?
@tediousjs/connection-string is a utility package designed to parse and format connection strings for use with the Tedious library, which is a TDS (Tabular Data Stream) protocol implementation for Node.js. This package helps in managing and manipulating connection strings for SQL Server databases.
What are @tediousjs/connection-string's main functionalities?
Parsing Connection Strings
This feature allows you to parse a connection string into a configuration object that can be used with the Tedious library. The `parseConnectionString` function takes a connection string and returns an object with the parsed details.
const { parseConnectionString } = require('@tediousjs/connection-string');
const connectionString = 'Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;';
const config = parseConnectionString(connectionString);
console.log(config);
Formatting Connection Strings
This feature allows you to format a configuration object into a connection string. The `formatConnectionString` function takes a configuration object and returns a connection string that can be used to connect to a SQL Server database.
const { formatConnectionString } = require('@tediousjs/connection-string');
const config = {
server: 'myServerAddress',
authentication: {
type: 'default',
options: {
userName: 'myUsername',
password: 'myPassword'
}
},
options: {
database: 'myDataBase'
}
};
const connectionString = formatConnectionString(config);
console.log(connectionString);
Other packages similar to @tediousjs/connection-string
pg-connection-string
The `pg-connection-string` package is used for parsing and formatting PostgreSQL connection strings. It provides similar functionality to @tediousjs/connection-string but is specifically designed for PostgreSQL databases. It can parse connection strings into configuration objects and format configuration objects back into connection strings.
connection-string
The `connection-string` package is a more general-purpose library for parsing and formatting connection strings for various databases. It supports multiple database types, including PostgreSQL, MySQL, and SQL Server, making it more versatile compared to @tediousjs/connection-string, which is specific to SQL Server.
Connection String Parser

This node library is designed to allow the parsing of Connection Strings see https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring
The library also provides the ability to parse SQL Connection Strings.
Usage
Parsing connection strings
The library comes with a generic connection string parser that will parse through valid connections strings and produce a key-value
map of the entries in that string. No additional validation is performed.
const { parseConnectionString } = require('@tediousjs/connection-string');
const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';
const parsed = parseConnectionString(connectionString);
console.log(parsed);
Output to the console will be:
{
"User id": "user",
"password": "password",
"initial catalog": "AdventureWorks",
"server": "MySqlServer"
}
Parsing SQL connection strings
There is a specific helper for parsing SQL connection strings and this comes with a value normaliser and validation. It also has an
option to "canonicalise" the properties. For many properties in an SQL connections string, there are aliases, when canonical properties
are being used, these aliases will be returned as the canonical property.
const { parseSqlConnectionString } = require('@tediousjs/connection-string');
const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';
const parsed = parseSqlConnectionString(connectionString, true);
console.log(parsed);
Output to console will be:
{
"user id": "user",
"password": "password",
"initial catalog": "AdventureWorks",
"data source": "MySqlServer"
}
NB: The Server
property from the connection string has been re-written to the value Data Source