Skip to content

Instantly share code, notes, and snippets.

@willshepp28
Created December 3, 2020 23:01
Show Gist options
  • Save willshepp28/c88495f87e1544b57adba75cd3fa98bf to your computer and use it in GitHub Desktop.
Save willshepp28/c88495f87e1544b57adba75cd3fa98bf to your computer and use it in GitHub Desktop.
app.js with dotenv bcrypt
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const bcrypt = require("bcrypt");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))
app.post("/", async(request, response) => {
if(!request.body.name || !request.body.password) {
return response.status(400).json({ message: "Missing credentials!!!"});
};
let user = {
name: request.body.name,
hash: await hash(request.body.password, process.env.saltRounds)
}
return response.status(201).json(user);
});
let hash = (password, saltRounds, ) => {
return bcrypt.hash(password, parseInt(saltRounds));
}
app.listen(3000, (request, response) => {
console.log("Server listening on Port: 3000");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment