Created
December 3, 2020 23:01
-
-
Save willshepp28/c88495f87e1544b57adba75cd3fa98bf to your computer and use it in GitHub Desktop.
app.js with dotenv bcrypt
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
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