Articles → AWS SDK AND NODE.JS → Connect To AWS RDS Using Node.Js

Connect To AWS RDS Using Node.Js






Steps




  1. Create a publicly accessible database.
  2. Create a node.js program to access RDS.
  3. Output.



Create A Publicly Accessible Database





Create A Node.Js Program To Access RDS




var mysql = require('mysql');

var connection = mysql.createConnection({
  host     : '<Your database host>',
  user     : 'admin',
  password : 'test1234',
  port     : 3306
});

connection.connect(function(err) {
  if (err) {
    console.error('Database connection failed: ' + err.stack);
    return;
  }

  console.log('Connected to database.');
});

connection.end();





Output




npm install mysql




Picture showing the status of the RDS database as connected
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, January 27, 2022

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250