Skip to content

Instantly share code, notes, and snippets.

@willgvfranco
Last active April 19, 2021 13:17
Show Gist options
  • Save willgvfranco/fd4f7940548031383741a68a8a70f69c to your computer and use it in GitHub Desktop.
Save willgvfranco/fd4f7940548031383741a68a8a70f69c to your computer and use it in GitHub Desktop.
node-js-react
let single_or_array = ['a']
Array.isArray(single_or_array) ? single_or_array.map(d => console.log(d)) : console.log(single_or_array)
import mongodb from 'mongodb';
const { MongoClient } = mongodb
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'NAME'
// const id = new ObjectID()
// console.log(id)
MongoClient.connect(connectionURL, { useUnifiedTopology: true }, (error, client) => {
if (error) {
return console.log('Unable to connect to database!')
}
const db = client.db(databaseName)
console.log('Connected correctly!')
// db.collection('users').insertOne({
// name: 'Test',
// age: 111
// }, (error, result) => {
// if (error) {
// return console.log('Unable to insert user')
// }
// console.log(result.ops)
// })
})
process.env.UV_THREADPOOL_SIZE = 2;
// Windows -> set UV_THREADPOOL_SIZE=7 && node threads.js
const crypto = require('crypto')
const start = Date.now();
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => {
console.log('1:', Date.now() - start);
});
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => {
console.log('2:', Date.now() - start);
});
console.log('1:', Date.now() - start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment