Currently, I am testing LevelDB as a key–value store for my Node.js projects, but I am having this issue: when I import Level and run the sample code from the website, leveljs.org, I get this error:
TypeError: level is not a function
at Object.<anonymous> (/home/runner/level/index.js:2:12)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
I have searched for this error and nothing has came up. I have tried importing Level in different ways and none of them have worked. Here is my code, which is identical to the sample code on the website:
const level = require('level')
const db = level('./db', { valueEncoding: 'json' })
db.put('key', { example: true }, function (err) {
if (err) throw err
db.get('key', function (err, value) {
if (err) throw err
console.log(value)
})
})
When in doubt, always check the documentation at GitHub:
The README also has this note:
Version 8.0.0 (released 2022-03-25) states:
It also notes:
The changelog lists this as a breaking change:
The website is outdated (as of 2022-12-22, 22:09:03 UTC), and below the code sample it says:
But you’re almost certainly using 8.0.0, not 5.0.0.
Shortly after bringing it up on the repository for leveljs.org, they fixed it.