Skip to content

Instantly share code, notes, and snippets.

View pablocattaneo's full-sized avatar

Pablo Cattaneo pablocattaneo

View GitHub Profile
.avoid-clicks {
pointer-events: none;
}
/* Example: https://davidwalsh.name/demo/pointer-events.php */
@pablocattaneo
pablocattaneo / how_to_compile_a_sass_file.zsh
Created January 25, 2019 13:49
How to compile a Sass file? #Sass Source: https://sass-lang.com/guide
sass --watch input.scss output.css
app.use('/images', express.static(path.join(__dirname, path_folder_storaging_images)))
// Example
const path = require('path')
app.use('/images', express.static(path.join(__dirname, 'images')))
.collection('collectionName').findOne({key:value})
// Example
const db = require('../db')
const ObjectId = require('mongodb').ObjectId
exports.getUser = ((req, res) => {
console.log('getUser')
filter = {
_id: new ObjectId(req.params.userId)
}
db.collectionName.find({ key:value })
// Example:
db.usersToSendEmail.find({_id: ObjectId("5c405972f3d33522c6242d31")})
const inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
const result = inventory.find( fruit => fruit.name === 'cherries' );
console.log(result) // { name: 'cherries', quantity: 5 }
// String required
body('name')
.trim()
.not().isEmpty()
.withMessage('This field is required')
.isString()
.withMessage('This field must be an string')
// Email required
@pablocattaneo
pablocattaneo / not_empty_validation.js
Created January 17, 2019 10:15
How to validate that an input is not empty in express using express-validator? #expressValidator
// body('name').not().isEmpty()
// Example
router.post('/insert', [
body('name')
.trim()
.not().isEmpty()
.withMessage('This field is required'),
body('email')
<!-- This simple form uses the novalidate attribute to turn off the browser's automatic validation; -->
<form novalidate>
<p>
<label for="mail">
<span>Please enter an email address:</span>
<input type="email" id="mail" name="mail">
<span class="error" aria-live="polite"></span>
</label>
</p>
<button>Submit</button>
@pablocattaneo
pablocattaneo / solve_CORS.js
Last active January 15, 2019 11:41
How to solve CORS problems in Express? #Express #node #CORS Source: https://www.udemy.com/nodejs-the-complete-guide/learn/v4/t/lecture/12087628?start=15
// In the entry file often index.js or app.js
const express = require('express')
const app = express()
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*') // The second parámeter could be a list of domains
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')
next()