Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js SQL Connection

A simple and scalable Node.js project demonstrating how to connect and interact with an SQL database using Node.js. This project can be used as a starter template for backend applications requiring database connectivity.

Features

  • SQL database connection setup
  • Environment variable configuration
  • Clean project structure
  • Query execution support
  • Error handling for database operations
  • Easy to extend for APIs and backend services

Tech Stack

  • Node.js
  • Express.js
  • SQL Database
  • JavaScript
  • dotenv

Project Structure

nodejs_sql_connection/
│── config/
│   └── db.js
│── routes/
│── controllers/
│── package.json
│── .env
│── server.js
│── README.md

Installation

Clone the repository:

git clone https://github.com/bhavyathashetty/nodejs_sql_connection.git

Move into the project directory:

cd nodejs_sql_connection

Install dependencies:

npm install

Environment Variables

Create a .env file in the root directory and add the following:

DB_HOST=localhost
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
DB_PORT=1433
PORT=5000

Running the Project

Start the development server:

npm start

Or with nodemon:

npm run dev

Server will run on:

http://localhost:5000

Example Database Connection

const sql = require("mssql");

const config = {
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  server: process.env.DB_HOST,
  database: process.env.DB_NAME,
  port: Number(process.env.DB_PORT),
  options: {
    encrypt: false,
    trustServerCertificate: true,
  },
};

sql.connect(config)
  .then(() => {
    console.log("Database Connected");
  })
  .catch((err) => {
    console.log(err);
  });

The setup commonly uses packages like mssql for SQL Server connectivity in Node.js. (GitHub)


Scripts

npm start       # Start server
npm run dev     # Run with nodemon

Future Improvements

  • Add CRUD operations
  • Implement authentication
  • Add ORM integration
  • Docker support
  • Unit and integration testing
  • Deployment configuration

Contributing

Contributions are welcome. Feel free to fork the repository and submit a pull request.


License

This project is licensed under the MIT License.


Author

Bhavyatha Shetty

Software Developer focused on backend development, Node.js, TypeScript, and scalable application architecture.

GitHub: Bhavyatha Shetty GitHub Profile

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages