Node API With SQL Server

Introduction

Node js is an open source server-side runtime environment. It provides asynchronous programming which means no blocking of a task. Due to this, it is faster than other frameworks. Node js is cross-platform that runs on Windows, Linux, and Mac. So, we can create a server-side application using JavaScript which is very fast and lightweight. Let us start building an application with node.
 
Description

Before we begin with node, we have to make sure that we have installed the node.js on our system. So, follow the following link and download node setup according to your operating system. Click here to download node setup After installing it successfully, go to your Start window and search for (Node.js command prompt). Open it and let's start with this.
 
Step 1

Write the following commands in your Node.js command prompt.
  1. F:\Projects>mkdir NodeApiWithSql  
  2. F:\Projects>cd NodeApiWithSql  
  3. F:\Projects\NodeApiWithSql>npm init  
It will create a file in your NodeApiWithSql folder with the name package.json with some basic information regarding your application.



You can see in the above image that it has created a file with the name, package.json, with the information related to your application. Now, let's see what we have in the package.json file.



You can see that in main, "index.js" is written in the package.json file. So, let's create a JS file with the name index in your folder. And let's install some required packages we need in our application with Node js command prompt.
Write the following commands in command prompt.



We have installed three packages here.
  • npm install express - is used for minimalist web framework for node.
  • npm install body-parser - body-parser incoming request bodies in a middleware.
  • npm install mssql - is used for using SQL Server database.
You can see more description regarding above packages at www.npmjs.com/package/
Ebook Download
View all
Learn
View all