Create Node.js apps using SQL Server on macOS
In this section, you will get SQL Server 2017 running on Docker. After that, you will install the necessary dependencies to create Node.js apps with SQL Server locally on your Mac.
Step 1.1 Install SQL Server
- In order to run SQL Server on your Mac, we are going to use the SQL Server on Linux Docker Image. For this, you need to install Docker for Mac.
- Configure at least 4GB of memory for your Docker environment, also consider adding multiple cores if you want to evaluate performance. You can do this in the Preferences - Advanced option on the menu bar.
- Next, start a new Terminal prompt and use the following commands to download and start the SQL Server on Linux Docker image. Make sure to use a strong password with special characters.
sudo docker pull microsoft/mssql-server-linux
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
You now have SQL Server running locally in Docker! Check out the next section to continue installing prerequisites.
Step 1.2 Install Homebrew and Node.js
-
Install Homebrew.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
Restart the terminal session.
-
Install Node.js
brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-6.7.0.el_captian.bottle.tar.gz ################################################################## 100.0% ==> Pouring node-6.7.0.el_captian.bottle.tar.gz ... ==> Using the sandbox ==> Caveats Please note by the default... ... ==> Summary /usr/local/Cellar/node/6.7.0: 3,669 files, 40.8M
You now have Node.js installed! The next section will walk you through getting the tools to interact with your database.
Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
SQLCMD for Mac is a command line utility that enables you to connect to SQL Server and run queries.
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
ACCEPT_EULA=y brew install msodbcsql mssql-tools
After installing SQLCMD, you can connect to SQL Server using the following command:
sqlcmd -S 127.0.0.1 -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 the STDOUT.
sqlcmd -S 127.0.0.1 -U sa -P your_password -Q "SELECT @@VERSION"
--------------------------------------------------------
Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64)
Apr 13 2017 11:44:40
Copyright (c) Microsoft Corporation
on Linux (Ubuntu 16.04)
1 rows(s) returned
Executed in 1 ns
You have successfully installed SQL Server Command Line Utilities on your macOS
You now have everything you need to start writing Node.js apps with SQL Server!
Have Questions?
Happy to help! You can find us on GitHub, MSDN Forums, and StackOverflow. We also monitor the #SQLServerDev hashtag on Twitter.