node.jssqliteraspberry-piraspberry-pi4node-sqlite3

Raspberry Pi 4: Error: Cannot find module 'sqlite3'


Status of sqlite3 installation on my Raspberry Pi 4 B when queried from the terminal:

pi@raspberrypi:~ $ sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0alt1
pi@raspberrypi:~ $ sqlite3
SQLite version 3.27.2 2019-02-25 16:06:06
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> 

For me it is confirmation that installation is complete. Also, I did not do any thing like creating a table or etc. I just installed it. Now I am trying to access it.

My code:

const sqlite3 = require('sqlite3').verbose();

Response:

internal/modules/cjs/loader.js:638
    throw err;
    ^
Error: Cannot find module 'sqlite3'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)

Don't know why it says cannot find sqlite3 when terminal clearly shows its installation and ability to access sqlite3?


Solution

  • The binary executable named sqlite3 and the Node.js module named sqlite3 are not the same thing.

    You need to install the Node.js module to use the Node.js module.