L
L
Lech2017-10-18 22:14:24
SQLite
Lech, 2017-10-18 22:14:24

NW.js + SQLite = how to make it work???

Good afternoon.
I decided to study NW.JS and wanted to use one of my old crafts as a project, rewriting it for this framework. The matter is that in the old project, for data storage, the SQLite DB is used.
But since I've never come across NW.JS before, as well as NODE.JS, I'm probably doing something wrong, because when I try to repeat the primitive example (below), in dev.tools I get: Uncaught Error: Cannot find module 'sqlite3', even though package.json even says "dependencies": {"sqlite3": "^3.1.13"}.
The example itself:

var sqlite3 = require('sqlite3').verbose();
      var db = new sqlite3.Database('database.sqlite');

      db.serialize(function() {

        db.run("CREATE TABLE if not exists user_info (info TEXT)");
        var stmt = db.prepare("INSERT INTO user_info VALUES (?)");
        for(var i = 0; i < 10; i++) {
          stmt.run("Ipsum " + i);
        }
        stmt.finalize();

        db.each("SELECT rowid AS id, info FROM user_info", function(err, row) {
          console.log(row.id + ": " + row.info);
        });
      });

    db.close();

NODE.JS 8.7.0 - installed from scratch with an installer, with registration in PATH.
NW.JS 0.25.4 - both regular and SDK.
SQLite installed and as written here - www.technerium.ru/nwjs/vklyuchenie-sqlite3-v-proek... and already on another OS via npm install sqlite3 --build-from-source, with pre-installation npm install --global --production windows-build-tools
The error is probably stupid, but due to lack of experience - I can't figure out where to dig.
Everything tested on Win10 x64 and Win7 x86 with all updates at the time of writing this post.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leha, 2017-10-19
@outcome

Nikita Polevoy gave the correct answer to the problem, though in a clarifying question. You can't mark a clarification as a solution. So I'm posting it here.
The problem was that the SQLite module was installed outside the project folder.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question