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.
- 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
- Node.js
- Express.js
- SQL Database
- JavaScript
- dotenv
nodejs_sql_connection/
│── config/
│ └── db.js
│── routes/
│── controllers/
│── package.json
│── .env
│── server.js
│── README.mdClone the repository:
git clone https://github.com/bhavyathashetty/nodejs_sql_connection.gitMove into the project directory:
cd nodejs_sql_connectionInstall dependencies:
npm installCreate 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=5000Start the development server:
npm startOr with nodemon:
npm run devServer will run on:
http://localhost:5000const 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)
npm start # Start server
npm run dev # Run with nodemon- Add CRUD operations
- Implement authentication
- Add ORM integration
- Docker support
- Unit and integration testing
- Deployment configuration
Contributions are welcome. Feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License.
Software Developer focused on backend development, Node.js, TypeScript, and scalable application architecture.
GitHub: Bhavyatha Shetty GitHub Profile