Create Node.js apps using SQL Server on Windows
In this section, you will get SQL Server 2017 on Windows. After that you will install the necessary dependencies to create Node.js apps with SQL Server
Step 1.1 Install SQL Server
- If you don’t have SQL Server 2017 Developer (or above) installed, click here to download the SQL Server exe.
- Run it to start the SQL installer.
- Click Basic in Select an installation type.
- Click Accept after you have read the license terms.
- (Optional) if you need to, you can choose a custom installation location for SQL Server.
- Click Install to proceed with the installation.
You now have SQL Server installed and running locally on your Windows computer! Check out the next section to continue installing prerequisites.
Step 1.2 Install Chocolatey and Node.js
If you already have Node.js and choco installed on your machine, skip this step. Install Chocolatey using this command in an elevated Command prompt (run as administrator).
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
For choco to work, you now need to restart the terminal session by closing and opening the command prompt. Open an elevated Command prompt (run as administrator) and run the following commands to install node:
choco install -y nodejs
Installing the following packages: nodejs The install of nodejs was successful. Software install location not explicitly set, could be in package or default install location if installer. Chocolatey installed 1/1 packages. 0 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
You have succesfuly installed Node.js and Chocolatey on your machine!
Step 1.3 Install sqlcmd - A Command Line Utility for SQL Server
SQLCMD is a command line tool that enables you to connect to SQL Server and run queries.
After installing SQLCMD, you can connect to SQL Server using the following command from a CMD session:
sqlcmd -S localhost -U sa -P your_password 1> # You're connected! Type your T-SQL statements here. Use the keyword 'GO' to execute each batch of statements.
This how to run a basic inline query. The results will be printed to STDOUT.
sqlcmd -S localhost -U sa -P yourpassword -Q "SELECT @@VERSION"
-------------------------------------------------------- Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) Apr 29 2016 23:23:58 Copyright (c) Microsoft Corporation Developer Edition (64-bit) 1 rows(s) returned Executed in 1 ns.
You have successfully installed SQL Server Command Line Utilities on your Windows machine!