Open In App

How to Set Online SQL Server for Node.js ?

An Online SQL server helps to connect your project with an online server instead of localhost database setup. To achieve this, the remotemysql site is popular for providing an online database to store our data in a secure way. 

Installation of sql module:



npm install sql
npm version sql
node index.js

Filename: index.js 




const mysql = require('mysql')
 
const connection = mysql.createConnection({
    host:'remotemysql.com',
    user:'Your_Username',
    password:'Your_Password',
    database:'Your_Database'
})
 
connection.query('SELECT NOW()', function(error, result){
    if(error) throw error
    console.log(result)
})

Steps to run the program:



npm install sql
node index.js

So this is how you can set up an online SQL server setup using remotemysql website.

Article Tags :