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
INSERT INTO `product` (`id`, `name`, `sku`, `price`, `quantity`) VALUES | |
(1, 'Toilet paper 10 pack', 'TP0001', 750, 1), | |
(2, 'Rice 1 Kg', 'RI0002', 140, 500), | |
(3, 'Pasta 500 g', 'PA0003', 260, 500), | |
(4, 'Chicken Breast 1 Kg', 'CB0004', 1200, 500), | |
(5, 'Hand Sanitizer', 'HS0005', 300, 500); |
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
CREATE TABLE `product` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | |
`sku` char(6) COLLATE utf8_unicode_ci NOT NULL, | |
`price` int(11) NOT NULL COMMENT 'in cents', | |
`quantity` int(11) NOT NULL, | |
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
PRIMARY KEY (`id`), | |
UNIQUE INDEX `sku` (`sku` ASC) VISIBLE |
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 mysql = require('mysql2/promise'); | |
const config = require('./config'); | |
async function createOrder() { | |
const items = ['RI0002', 'CB0004'] | |
const connection = await mysql.createConnection(config.db); | |
await connection.execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED'); | |
console.log('Finished setting the isolation level to read committed'); | |
//set wait timeout and lock wait timeout as per need. | |
await connection.beginTransaction(); |
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 express = require('express'); | |
const app = express(); | |
const logger = require('npmlog'); | |
const port = 3005; | |
//more docs here - https://github.com/npm/npmlog#basic-usage | |
app.get('/', (req, res) => { | |
res.send('Hello World! - npmlog logged'); | |
}); |
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
Example app listening at http://localhost:3004 | |
Loglevel is simple |
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 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'); |
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
Example app listening at http://localhost:3003 | |
{"level":30,"time":1611695678813,"pid":32768,"hostname":"abcd","req":{"id":1,"method":"GET","url":"/api/test","headers":{"host":"localhost:3003","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.9","sec-fetch-site":"none","sec-fetch-mode":"navigate","sec-fetch-user":"?1","sec-fetch-dest":"document","accept-encoding":"gzip, deflate, br","accept-language":"en-GB,en-US;q=0.9,en;q=0.8","cookie":"_ga=GA1.1.1863215728.1591927460; PPA_ID=gkq1qhp7htr141pkojpmqcqt95; webfx-tree-cookie-persistence=wfxt-4; io=TxK-RQvnHb14VONKAAAC","if-none-match":"W/\"19-JzA5ewGlTSyvFTwS4fIYMkA |
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 expressWinston = require('express-winston'); | |
const express = require('express'); | |
const app = express(); | |
const port = 3001; | |
//more options here - https://github.com/bithavoc/express-winston#request-logging | |
app.use(expressWinston.logger({ | |
transports: [ | |
new winston.transports.Console() |
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
Example app listening at http://localhost:3001 | |
{"meta":{},"level":"\u001b[32minfo\u001b[39m","message":"GET /api/test 304 2ms"} | |
{"meta":{},"level":"\u001b[32minfo\u001b[39m","message":"GET /favicon.ico 404 2ms"} | |
{"meta":{},"level":"\u001b[32minfo\u001b[39m","message":"GET /favicon.ico 404 1ms"} |
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
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 |