Reputation: 11
I would like to come and ask for help for an error that is making me mad. The famous "Sqlite3 module not found" I have sqlite3 in my json dependencies. It is installed in node modules. and I can't understand where this error comes from. I'm sending you the code for my "index.js" file
const express = require("express");
const app = express();
require("dotenv").config();
const jwt = require("jsonwebtoken");
const secret = process.env.JWT_SECRET;
const servicesRoutes = require("./routes/api/services");
const vehiclesRoutes = require("./routes/api/vehicles");
const contactRoutes = require("./routes/api/contact");
const usersRoutes = require("./routes/api/user");
const authRoutes = require("./routes/api/auth");
app.use("/auth", authRoutes);
app.use("/api/services", servicesRoutes);
app.use("/api/vehicles", vehiclesRoutes);
app.use("/api/contact", contactRoutes);
app.use("/api/users", usersRoutes);
app.use(express.json());
const user = {
id: 123,
username: "utilisateur123",
};
const receivedToken = token; // Utilisez le token JWT que vous souhaitez vérifier
jwt.verify(receivedToken, secret, (err, decoded) => {
if (err) {
console.error("Erreur de vérification du JWT :", err);
} else {
console.log("Données du JWT décryptées :", decoded);
}
});
const secretKey = secret; // Utilisez la valeur de la clé secrète
const token = jwt.sign(user, secretKey, { expiresIn: "1h" });
console.log("JWT :", token);
app.get("/", (req, res) => {
res.send("Hello World!");
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
$ npm start
[email protected] start node index.js
node:internal/modules/cjs/loader:1051 throw err; ^
Error: Cannot find module 'sqlite'
I deleted the nodemodule folder and did a "npm install" again but still the same error, I reinstalled sqlite "npm install sqlite3 --save" and nothing changes, still blocked, if anyone has a solution I'm interested!
Upvotes: 0
Views: 41
Reputation: 11
It's okay I ended up finding the problem, for those who this happens to. Just install sqlite3 in latest version, because the standard version does not take into account const { open } = require("sqlite")
;.Go and understand why
Upvotes: 1