For uni I'm working on node.js servers. I'm following the code used in the lectures and I got in trouble with persistent sessions in express.js. In the lecture slides the following require
is used:
var session = require('express-session');
var SQLiteStore = require('sqlite3')(session);
But when I used this in my code I get the following Error:
var SQLiteStore = require("sqlite3")(session);
^
TypeError: require(...) is not a function
at Object.<anonymous> (C:\Users\jordv\OneDrive\Documenten\UU\2022 -2023\Blok 3\Web Technology\test\server.js:12:37)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
I tried to find a solution for this online, and found this post NodeJs : TypeError: require(...) is not a function. I tried to understand the top answer but I just can't. I have two questions:
- In the linked post, immediately invoked functions are mentioned. Why is my code an immediately invoked function? (My thought is that the error message states that it is not a function, so how is it immediately invoked?)
- How is the answer to that post supposed to be applied to my situation?
EDIT:
In the comments it was suggested to console.log(sqlite3)
. this gives
{
Database: [Function: Database],
Statement: [Function: Statement],
Backup: [Function: Backup],
OPEN_READONLY: 1,
OPEN_READWRITE: 2,
OPEN_CREATE: 4,
OPEN_FULLMUTEX: 65536,
OPEN_URI: 64,
OPEN_SHAREDCACHE: 131072,
OPEN_PRIVATECACHE: 262144,
VERSION: '3.41.1',
SOURCE_ID: '2023-03-10 12:13:52 20399f3eda5ec249d147ba9e48da6e87f969d7966a9a896764ca437ff7e737ff',
VERSION_NUMBER: 3041001,
OK: 0,
ERROR: 1,
INTERNAL: 2,
PERM: 3,
ABORT: 4,
BUSY: 5,
LOCKED: 6,
NOMEM: 7,
READONLY: 8,
INTERRUPT: 9,
IOERR: 10,
CORRUPT: 11,
NOTFOUND: 12,
FULL: 13,
CANTOPEN: 14,
PROTOCOL: 15,
EMPTY: 16,
SCHEMA: 17,
TOOBIG: 18,
CONSTRAINT: 19,
MISMATCH: 20,
MISUSE: 21,
NOLFS: 22,
AUTH: 23,
FORMAT: 24,
RANGE: 25,
NOTADB: 26,
LIMIT_LENGTH: 0,
LIMIT_SQL_LENGTH: 1,
LIMIT_COLUMN: 2,
LIMIT_EXPR_DEPTH: 3,
LIMIT_COMPOUND_SELECT: 4,
LIMIT_VDBE_OP: 5,
LIMIT_FUNCTION_ARG: 6,
LIMIT_ATTACHED: 7,
LIMIT_LIKE_PATTERN_LENGTH: 8,
LIMIT_VARIABLE_NUMBER: 9,
LIMIT_TRIGGER_DEPTH: 10,
LIMIT_WORKER_THREADS: 11,
cached: { Database: [Function: Database], objects: {} },
verbose: [Function (anonymous)]
}