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
a = ["hello", "world"] | |
a.forEach ( (elem, idx, arr) => { | |
console.log(elem, "at: ", idx, "inside: ", arr) | |
}) | |
/* | |
hello at: 0 inside: [ 'hello', 'world' ] | |
world at: 1 inside: [ 'hello', 'world' ] | |
*/ |
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
class Person { | |
constructor(name) { | |
this.name = name | |
} | |
} | |
function greet(person) { | |
console.log(this.greeting.replace("$", person.name)) | |
} |
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
const fs = require("fs") | |
async function read(fname) { | |
return new Promise( (resolve, reject) => { | |
fs.readFile(fname, (err, content) => { | |
if(err) return reject(err) | |
resolve(content.toString()) | |
}) | |
}) | |
} |
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
const winston = require('winston'); | |
const Elasticsearch = require('winston-elasticsearch'); | |
const esTransportOpts = { | |
level: 'info' | |
}; | |
const logger = winston.createLogger({ | |
level: 'info', | |
format: winston.format.json(), |
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
//Logging tests... | |
logger.info("Test!") | |
logger.error("This is an error message!") | |
logger.error("This is an error message with an object!", { error: true, message: "There was a problem!"}) |
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
{ | |
"took": 994, | |
"timed_out": false, | |
"_shards": { | |
"total": 1, | |
"successful": 1, | |
"skipped": 0, | |
"failed": 0 | |
}, | |
"hits": { |
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
const esTransportOpts = { | |
level: 'info', | |
transformer: logData => { | |
return { | |
"@timestamp": (new Date()).getTime(), | |
severity: logData.level, | |
message: `[${logData.level}] LOG Message: ${logData.message}`, | |
fields: {} | |
} | |
} |
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
const esTransportOpts = { | |
level: 'info', | |
clientOpts: { | |
host: "http://your-host:your-port", | |
log:"info" | |
} | |
}; |
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
{ | |
"name": "Project name", | |
"version": "1.0.0", | |
"description": "This is a basic description", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Fernando Doglio", | |
"license": "ISC", |
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
let regExp = new RegExp('a|b'); |