Skip to content
Related Articles

Related Articles

How to Set Online SQL Server for Node.js ?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 22 Aug, 2022
View Discussion
Improve Article
Save Article

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:

  1. You can visit the link Install sql module. You can install this package by using this command.
npm install sql
  1. After installing sql you can check your sql version in command prompt using the command.
npm version sql
  1. After that, you can just create a folder and add a file for example index.js, To run this file you need to run the following command.
node index.js
  1. Now go to remotemysql official website and create an account and login, then go to your ‘DATABASES’ section and simply click on ‘CREATE NEW DATABASE’ button. After that you will see the details of your database as shown below: dashboard
  2. Now save these details as this will be required in connection code. Now click on ‘ACTION’ button which is just next to your recently created database and select ‘phpMyAdmin’. Now you will be redirected to your myPhpAdmin portal. Now login with username and password and there you go, you can now create tables and do all SQL operations.
  3. Now to connect with this database, write down the following code in your index.js file.

Filename: index.js 


const mysql = require('mysql')
const connection = mysql.createConnection({
connection.query('SELECT NOW()', function(error, result){
    if(error) throw error

Steps to run the program:

  1. The project structure will look like this: project structure
  2. Make sure you need install sql by using following commands:
npm install sql
  1. Run index.js file using below command:
node index.js
  1. Output of above command

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!