Installation
Installation is simple, following normal Node expectations.
With NPM
cd <your-project-directory>
npm install tedious
Of course, if your project's package.json declares a dependency on tedious then it's even simpler. .
cd <your-project-directory>
npm install
Manually
Copy the directory containg tedious in to your project'snode_modules
directory.
Installing SQL Server on Docker in Windows
- Checkout the official docker images
-
In Powershell:
- Pull the docker image:
docker pull mcr.microsoft.com/mssql/server:2019-latest
- Start the SQL Server:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password_01" -p 1433:1433 -v sqldatavol:/var/opt/mssql -d
-
Note: Data should be preserved in sqldatavol in the event the container is stopped or removed. To
check, run
Docker volume ls
or visit here for more information about data persistence.
-
Note: Data should be preserved in sqldatavol in the event the container is stopped or removed. To
check, run
- In your javascript file running tedious, set the config to something like:
var config = { "server": "0.0.0.0", "authentication": { "type": "default", "options": { "userName": "sa", "password": "password_01" } }, "options": { "port": 1433, "database": "master", "trustServerCertificate": true } }
- Verify that the server has been setup and `tedious` is able to connect by running the query:
// file.js const Request = require('tedious').Request; const Connection = require('tedious').Connection; const connection = new Connection(config); connection.on('connect', (err) => { if (err) { console.log('Connection Failed'); throw err; } executeStatement(); }); connection.connect(); function executeStatement() { const request = new Request("select 42, 'hello world'", (err, rowCount) => { if (err) { throw err; } console.log('DONE!'); connection.close(); }); // Emits a 'DoneInProc' event when completed. request.on('row', (columns) => { columns.forEach((column) => { if (column.value === null) { console.log('NULL'); } else { console.log(column.value); } }); }); // In SQL Server 2000 you may need: connection.execSqlBatch(request); connection.execSql(request); }
- Expected output:
42 hello world 1 rows returned DONE!
- Pull the docker image: