mssql
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.MSSQL is a popular npm package that serves as a Microsoft SQL Server client for Node.js. It allows Node.js applications to interact with SQL Server databases, streamline database queries, and enact safe handling of different data types.
Here are some examples of how you can use mssql:
Installation:
npm install mssql
Connect to Microsoft SQL Server using a connection string:
const sql = require('mssql')
async () => {
try {
await sql.connect('Server=localhost,1433;Database=database;User Id=username;Password=password;Encrypt=true')
const result = await sql.query`select * from mytable where id = ${value}`
console.dir(result)
} catch (err) {
// error checks
}
}
Or, use a configuration object to connect to the database:
const sql = require('mssql')
const sqlConfig = {
user: process.env.DB_USER,
password: process.env.DB_PWD,
database: process.env.DB_NAME,
server: 'localhost',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
},
options: {
encrypt: true, // for azure
trustServerCertificate: false // change to true for local dev/self-signed certs
}
}
async () => {
try {
await sql.connect(sqlConfig)
const result = await sql.query`select * from mytable where id = ${value}`
console.dir(result)
} catch (err) {
// ... error checks
}
}
The comprehensive documentation for mssql is available directly on the GitHub page of the project: git+https://github.com/tediousjs/node-mssql.git. This provides detailed sections on different features, functionalities, methods, and classes available in the npm package, along with examples and instructions for different scenarios.