To fix Node npm install doesn’t create node_modules directory, we create a package.json file.
To do this, we run
npm init
to create a package.json file in the project folder.
To fix Node npm install doesn’t create node_modules directory, we create a package.json file.
To do this, we run
npm init
to create a package.json file in the project folder.
To fix Node.js https pem error: routines:PEM_read_bio:no start line,. we read the SSL key and certificate file.
For instance, we write
const options = {
key: fs.readFileSync("./key.pem", "utf8"),
cert: fs.readFileSync("./server.crt", "utf8"),
};
to read key and cert files with readFileSync.
key is the key file.
And cert is the certificate file.
To fix Passport.js in Node not removing session on logout, we call the session.destroy method.
For instance, we write
app.get("/logout", (req, res) => {
req.session.destroy((err) => {
res.redirect("/");
});
});
to call req.session.destroy to destroy the session.
We call it with a callback that’s called when the session is destroyed.
And we call redirect in the callback to redirect to /.
To retrieve last inserted id with Node MySQL, we use the insertedId property.
For instance, we write
connection.query(
"INSERT INTO posts SET ?",
{ title: "test" },
(err, result, fields) => {
if (err) throw err;
console.log(result.insertId);
}
);
to call query with a callback that gets the result.insertId property to get the ID of the last inserted item.
To fix Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE during PhoneGap installation with Node, we disable the strict-ssl option.
To do this, we run
npm config set strict-ssl false
to disable the strict-ssl option to make npm accept untrusted SSL certificates.
Then we run
npm config set strict-ssl true
after installation to turn the certificate check back on.