Node.js API to connect to Oracle Database and retrieve data from views.
- Express.js REST API
- Oracle Database connection using oracledb
- CORS enabled for Vue.js frontend
- Environment-based configuration
- Connection pooling for better performance
- Node.js (v14 or higher)
- Oracle Instant Client installed on Windows Server
- Oracle Database access
- Clone the repository:
git clone <your-repo-url>
cd nodejs-oracle-api- Install dependencies:
npm install- Configure environment variables:
- Copy
.env.exampleto.env - Update the values in
.envwith your Oracle database credentials:
DB_USER=your_oracle_username
DB_PASSWORD=your_oracle_password
DB_HOST=your_database_host
DB_PORT=1521
DB_SERVICE_NAME=ORCL
PORT=3000
FRONTEND_URL=http://localhost:8080- Update the view name in
controllers/dataController.js:
- Replace
YOUR_VIEW_NAMEwith your actual Oracle view name
- Download Oracle Instant Client from Oracle website
- Extract to
C:\instantclient_23_0(or your preferred location) - Add the path to System Environment Variables (PATH)
- Uncomment and update the path in
config/database.js:
oracledb.initOracleClient({ libDir: 'C:\\instantclient_23_0' });Development mode (with nodemon):
npm run devProduction mode:
npm startGET /- API informationGET /api/health- Health checkGET /api/data- Get data from Oracle view
{
"success": true,
"count": 10,
"data": [
{
"NAME": "Item 1",
"STATUS": "Active"
},
{
"NAME": "Item 2",
"STATUS": "Inactive"
}
]
}- Install iisnode module for IIS
- Create a new website in IIS
- Point the physical path to your project directory
- Create a
web.configfile in the root directory - Configure the .env file with production values
- Restart IIS
nodejs-oracle-api/
├── config/
│ └── database.js # Database configuration
├── controllers/
│ └── dataController.js # API controllers
├── routes/
│ └── api.js # API routes
├── .env # Environment variables (not in git)
├── .env.example # Environment variables example
├── .gitignore
├── package.json
├── server.js # Main server file
└── README.md
If you get "DPI-1047: Cannot locate a 64-bit Oracle Client library":
- Make sure Oracle Instant Client is installed
- Add the Instant Client path to System PATH
- Uncomment the
initOracleClientline inconfig/database.js
If you get connection errors:
- Verify database credentials in .env
- Check if the database is accessible from the server
- Verify the service name is correct
ISC