Static IP address path


#1

Hi,

I am trying to access an sqlite file on a local area network server located in “sqlite” folder, on windows file explorer I access it using the IP address “192.168.5.15/sqlite/db.sqlite”, however when the electron aplication tries to access it, the path is converted to the local machine path “c:/application …/192.168 …”.

please how can I just point the file directly using the static IP adress without converting it to local machine path?


#2

Have you tried explicitly setting the protocol with http://?


#3

yes it convert it back to c:/application/ …/http://


#4

You might have to share your code to provide more context.


#5

// login_app.js

var route = require(’…/…/libs/router.js’); //my lib

var dbPath = “192.168.5.15/sqlite/db.sqlite” // here is the problem

function login() {
var email = document.getElementById(“email”).value;
var password = document.getElementById(“password”).value;

if(email == "" || password == ""){
    alert("Please Enter Your email & Password ...");
    return;
} else{
    var sql = require('sql.js');                            //Import sqLite 
    var fs = require("fs");                                 //Import Files driver

    var SHA256 = require("crypto-js/sha256");              	//Crypting Library

    try {
        var filebuffer = fs.readFileSync(dbPath);			//here it converts the file to lical machine

        if (filebuffer != null) {
            var db = new SQL.Database(filebuffer);
        } else {
            var db = new SQL.Database();
            console.log("No Database");
        }

        // Prepare an sql statement
        var stmt = db.prepare("SELECT * FROM users WHERE email=:emailid");

        // Bind values to the parameters and fetch the results of the query
        var result = stmt.getAsObject({':emailid' : email});
        if(result.password == null) alert('Account not existing, please contact Your Administrator ...');
        else{
            if(SHA256(password) == result.password) {
                
                route.data.relocate('dashboard');

            }
            else alert('Wrong Login credentials, please try again ...');
        }

    } catch (e) {
        console.log(e);
    }

}  

}


#6

I suspect that the problem is that you’re using fs when you should be using http or https.


#7

but in order to use sql.js I need to use fs, is there any other way to read sqlite database without fs??


#8

I am not sure how to explain you that, but it is not apache server, it just a computer with shared folders


#9

You’re accessing a different computer via an IP address. fs seems to be getting confused about that.

More broadly, I’m not sure how this problem has anything to do with Electron. Maybe you should be looking at forums with broader communities of Node developers and asking them if they’ve done work accessing databases on remote machines. Alternatively, you could mount the remote machine as a drive with an SSHFS and use fs with that.


#10

It is so simple, I just had to use double slash “//” and it worked fine:

var dbPath = “//192.168.5.15/sqlite/db.sqlite”;

Thank you for your time.


#11

Glad you found something that worked. :slight_smile: