This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shows hashing passwords through famous npm package bcrypt | |
const bcrypt = require("bcryptjs") | |
const myFunction = async () => { | |
const password = "thisisapassword" | |
const hashedPassword = await bcrypt.hash(password, 8) | |
console.log(password) | |
console.log(hashedPassword) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// we are going to explore jsonwebtoken methods | |
const jwt = require("jsonwebtoken") | |
const myFunction = async () => { | |
const token = jwt.sign({ _id: "abcdefg" }, "anysecretkey", { | |
expiresIn: "10 seconds" | |
}) | |
console.log(token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bcrypt = require("bcryptjs") | |
const mongoose = require("mongoose") | |
// we need to design a schema first of all | |
const userSchema = new mongoose.Schema({ | |
name: { | |
type: String | |
}, | |
password: { | |
type: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is a file in the root folder | |
const User = require("./models/user.js"); | |
const main = async () => { | |
// to show tasks saved by a particular user | |
const user = await User.findById("5e54b46f3022d70b2ceaf2e5") | |
// console.log(user.tasks) --> without virtual (returns undefined, as tasks ain't a field) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.js >>> root file of /src | |
const multer = require("multer") | |
const express = require("express") | |
const app = express() | |
const upload = multer({ | |
dist: "images" | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const multer = require("multer") | |
const express = require("express") | |
const app = express() | |
const storage = multer.diskStorage({ | |
destination: function (req, file, cb) { | |
cb(null, __dirname + "/uploads") | |
}, | |
filename: function (req, file, cb) { | |
const firstname = file.originalname.split(".")[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require("mongoose") | |
mongoose.connect("mongodb://127.0.0.1:27017/whatever-you-call", { | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useUnifiedTopology: true, | |
useFindAndModify: false | |
}); | |
// connect to database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require("jsonwebtoken") | |
const User = require("../models/user") | |
const auth = async (req, res, next) => { | |
try { | |
const token = req.header("Authorization").replace("Bearer", "") | |
const decoded = jwt.verify(token, "thegivensecret") | |
const user = await User.findOne({ | |
_id: decoded._id, | |
"tokens.token": token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Let all the boilerplate here --> | |
<svg class="my-svg-class"> | |
<use xlink:href="img/sprite.svg#icon-whatever"></use> | |
</svg> | |
<!-- I bought the svg from IconMoon.io then made all the code inside sprite.svg | |
and targeted the icon name followed by # --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/contact" method="post"> | |
<label>TITLE</label> | |
<label> | |
<input type="radio" name="title" value="mr">Mr | |
</label> | |
<label> | |
<input type="radio" name="title" value="mrs">Mrs | |
</label></br> | |
<label>First name</label></br> | |
<input type="text" name="first_name"></br> |
OlderNewer