Skip to content

Instantly share code, notes, and snippets.

View geshan's full-sized avatar

Geshan Manandhar geshan

View GitHub Profile
@geshan
geshan / Markdium-JavaScript.js
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const express = require('express');
const app = express();
const logger = require('loglevel');
const port = 3004;
//more docs here - https://github.com/pimterry/loglevel#documentation
app.get('/', (req, res) => {
res.send('Hello World! - loglevel logged');
});
@geshan
geshan / Markdium-Shell.bash
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
Example app listening at http://localhost:3005
WARN From Npmlog Npmlog is simple too {"message":"test"}
@geshan
geshan / Markdium-JavaScript.js
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const express = require('express');
const app = express();
const port = 3002;
//more options here - https://github.com/villadora/express-bunyan-logger#usage
app.use(require('express-bunyan-logger')({
name: 'logger',
format: ":remote-address - :user-agent[major] custom logger",
streams: [{
level: 'info',
@geshan
geshan / Markdium-JavaScript.js
Created March 13, 2021 10:32
Markdium-Javascript memoization: a practical example for better HTTP performance
const express = require('express');
const router = express.Router();
const quotes = require('../services/quotes');
const pMemoize = require('p-memoize');
const ONE_MINUTE_IN_MS = 60000;
const memGetMultiple = pMemoize(quotes.getMultiple, {maxAge: ONE_MINUTE_IN_MS});
/* GET quotes listing. */
router.get('/', async function(req, res, next) {
try {
@geshan
geshan / Markdium-JavaScript.js
Created March 13, 2021 10:32
Markdium-Javascript memoization: a practical example for better HTTP performance
const express = require('express');
const router = express.Router();
const quotes = require('../services/quotes');
/* GET quotes listing. */
router.get('/', async function(req, res, next) {
try {
res.json(await quotes.getMultiple(req.query.page));
} catch (err) {
console.error(`Error while getting quotes `, err.message);
@geshan
geshan / Markdium-Shell.bash
Last active March 13, 2021 10:40
Markdium-Javascript memoization: a practical example for better HTTP performance
echo "GET https://geshan-nodejs-posgresql-memoize.zeet.app/quotes" \
| vegeta attack -duration=30s -rate=50 -output=results-veg-mem.bin && cat results-veg-mem.bin \
| vegeta plot --title="Quotes API after memozie" > quotes-api-after-memoize.html
@geshan
geshan / Markdium-Shell.bash
Last active March 13, 2021 10:42
Markdium-Javascript memoization: a practical example for better HTTP performance
echo "GET https://geshan-nodejs-posgresql.zeet.app/quotes" \
| vegeta attack -duration=30s -rate=50 -output=results-veg-no-mem.bin && cat results-veg-no-mem.bin \
| vegeta plot --title="Quotes API before memozie" > quotes-api-before-memoize.html
@geshan
geshan / Markdium-JavaScript.js
Created March 14, 2021 04:29
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const express = require('express');
const app = express();
const pino = require('express-pino-logger')();
const port = 3003;
//more options here - https://github.com/pinojs/express-pino-logger#example
app.use(pino)
app.get('/', (req, res) => {
res.send('Hello World! - Pino logged');
@geshan
geshan / Markdium-Shell.bash
Created March 14, 2021 04:29
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
Example app listening at http://localhost:3002
{"name":"logger","hostname":"abcd","pid":32691,"req_id":"0b2d2977-376e-4742-86b0-57feec630188","level":30,"remote-address":"::1","ip":"::1","method":"GET","url":"/api/test","referer":"-","user-agent":{"family":"Chrome","major":"87","minor":"0","patch":"4280","device":{"family":"Other","major":"0","minor":"0","patch":"0"},"os":{"family":"Mac OS X","major":"10","minor":"14","patch":"6"}},"http-version":"1.1","response-time":14.628108,"response-hrtime":[0,14628108],"status-code":304,"req-headers":{"host":"localhost:3002","connection":"keep-alive","sec-ch-ua":"\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"","sec-ch-ua-mobile":"?0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0
@geshan
geshan / Markdium-JavaScript.js
Created March 14, 2021 04:29
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const express = require('express');
const app = express();
const port = 3002;
//more options here - https://github.com/villadora/express-bunyan-logger#usage
app.use(require('express-bunyan-logger')({
name: 'logger',
format: ":remote-address - :user-agent[major] custom logger",
streams: [{
level: 'info',