hash
вместо hashSync
const crypto = require('crypto');
const util = require('util');
const cryptoPbkdf2 = util.promisify(crypto.pbkdf2);
let hashLength = 16;
let iterations = 10;
async function createSaltHash(email) {
let salt = crypto.randomBytes(hashLength).toString('base64');
let hash = (await cryptoPbkdf2(email, salt, iterations, hashLength, 'sha512')).toString();
return { salt, hash }
};
async function checkSaltHash(email, salt, hash) {
if (!email || !hash || !salt) return false;
let userHash = (await cryptoPbkdf2(email, salt, iterations, hashLength, 'sha512')).toString();
let check = userHash == hash;
return check;
};
Just because Node is designed without threads, doesn't mean you cannot take advantage of multiple cores in your environment. Child processes can be spawned by using our child_process.fork() API, and are designed to be easy to communicate with. Built upon that same interface is the cluster module, which allows you to share sockets between processes to enable load balancing over your cores.
module.exports.getUser = (req, res) => {
if (req.isAuthenticated() && req.user.role == 'user')
res.render('user');
}
module.exports.postChangeRole = (req, res) => {
console.log(req.body);
pg.connect(connectionString, function (err, client, done) {
console.log(req);
if (err) {
return console.error('error feetching client from pool', err);
}
client.query('UPDATE items SET role=($1), change=($2) WHERE name=($3)', [req.body.role,
req.body.role == 'user' ? 'true' : 'false', req.body.name]);
done();
});
}
var handlers=require('./handlers');
app.get('/user', handlers.getUser);
app.post('/changeRole',handlers.postChangeRole);
set NODE_PATH=./&&node index.js
set NODE_PATH=./
- это указание глобальной переменной NODE_PATH
на поиск модулей в проекте, по мимо node_modules. node index.js
- это запуск приложения. &&- это разделитель команд...
"scripts": {
...
"dev":"set NODE_PATH=./&&node index.js"
...
}
npm run dev
const env = require("config/env");