Skip to content
Build a Node.js App with SQL Server Tutorial
JavaScript Vue HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Build a Secure Node.js App with SQL Server

This is a sample application for the article Build a Secure Node.js App with SQL Server.

Built with love, using:


If you don't already have access to SQL Server, you can install one locally for development and testing.

Install SQL Server on Windows

Download and install SQL Server Developer Edition.

Install SQL Server on Mac or Linux

  1. Install Docker
  2. Run the following in a terminal. Change the values of name_your_container and SA_PASSWORD=P@55w0rd to what you desire.
docker pull microsoft/mssql-server-linux:2017-latest
docker run -d --name name_your_container -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=P@55w0rd' -e 'MSSQL_PID=Developer' -p 1433:1433 microsoft/mssql-server-linux:2017-latest

Note: For more information on running SQL Server for Linux, see SQL Server Running on a Mac?!

Set Up Local Development Environment

  1. Clone this repository (or download and extract the zip file)
  2. Open a command prompt or terminal
  3. Change to the directory that contains the project files
  4. Run npm install to install all the dependencies
  5. Copy .env.sample to .env, and modify the settings to match your environment
# hapi server configuration

# SQL Server connection
# Change SQL_ENCRYPT=true if using Azure

# Okta configuration

Initialize Your SQL Database

You will need a SQL database to for this application. If you are running SQL Server locally and don't already have a database, you can create one with the following script. You can use a utility like Azure Data Studio to connect to your instance to run this script.

USE master;

CREATE DATABASE calendar; -- change this to whatever database name you desire

Next you can run the following task at the command line or terminal to initialize your database.

Note: Make sure you have the correct server, database, user, and password configured in your .env file.

npm run tasks:initdb

Easily Add Authentication to Your Applications with Okta

This application uses Okta for authentication. To complete your development set up, you'll need an Okta developer account. Go to the Okta Developer Portal and sign up for a forever free Okta account.

After creating your account, click the Applications link at the top, and then click Add Application.

Next, choose a Web Application and click Next.

Enter a name for your application, such as Node-SQL. Then, click Done to finish creating the application.

Near the bottom of the application page you will find a section titled Client Credentials. Copy the Client ID and Client secret values and paste them into your .env file to replace {yourClientId} and {yourClientSecret}, respectively.

Click on the Dashboard link. On the right side of the page, you should find your Org URL. Copy and paste this value into your .env file to replace the value for OKTA_ORG_URL.

Next, enable self-service registration. This will allow new users to create their own account. Click on the Users menu and select Registration.

  1. Click on the Edit button.
  2. Change Self-service registration to Enabled.
  3. Click the Save button at the bottom of the form.

Run the Local Web Application

  1. Run npm run dev to start the development server
  2. Browse to http://localhost:8080

Run the Tests

> npm run test
You can’t perform that action at this time.