I am building a desktop application in NW.JS. Now, I want to store data in database using MySQL but I don't know how to add MySQL node module in my nw.js application. Kindly answer it in detail i am beginner. I added require('mysql');
but it says no mysql module exist
<script>
var sql = require('mysql');
var connection = mysql.createConnection({
host : 'locahost',
user : 'root',
password : '',
database : 'db_delvin'
});
<script>
On the command line (terminal) run the following command in the root folder of your project:
npm install mysql --save
the --save
appendix will save the dependency in the package.json
of your application
Every time you see a require
or import
in Javascript it means that a module is necessary to be loaded to charge dependency's functionalities. NW.js is a module loader for the DOM but it still requires the modules you want to use in your application to be installed.
Check the package.json
in the root of your application folder to see other required dependencies.