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
#!/usr/bin/env node | |
const os = require("os"); | |
console.log('Information about CPUs \n', os.cpus()); | |
// To run this script you need to apply the permision run executable -> chmod +x script.js | |
// The # allows to tell the shell run this script with node env |
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 to simulate a intesive work, sum the value recieved | |
* @param {number} value | |
*/ | |
const handlerHeavyOperation = (value = 0) => { | |
let res = value; | |
for (let i = 0; i < 90000; i++) { | |
res += i; | |
} | |
return res; |
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 EventEmitter = require("events"); | |
/** | |
* Example using EventEmitter to notify custom events | |
* The class extends from EventEmitter to use the methods | |
* emit: Emit the custom event with the payload | |
* on: Handler to listen any custom event, similar to a eventListener in Web | |
*/ | |
class Reviews extends EventEmitter { | |
constructor() { |
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
/** | |
* What pass when require a module? | |
* | |
* Steps | |
* | |
* 1. Resolving | |
* 2. Loading | |
* 3. Wrapping | |
* 4. Evaluating | |
* 5. Caching |
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
FROM node:16.13.0-alpine AS base | |
FROM base AS build | |
WORKDIR /usr/src/app | |
COPY . . | |
RUN npm ci --production | |
RUN npm run build | |
FROM base AS publish | |
COPY --from=build /usr/src/app/package.json /usr/src/app/package.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
// Retrieve the arguments pass to the process | |
// Skip the first arguments (node path | file path) | |
const [, , ...params] = process.argv; | |
console.log("params recieved in the process", process.argv); |
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 { promisify } = require("util"); | |
// Example legacy callback function with schema callback(err, response) | |
const legacyFunctionAPI = (name, callback) => { | |
setTimeout(() => { | |
if (Math.random() < 0.5) { | |
callback(null, { id: 2, name }); | |
} else { | |
callback(new Error("The API has fail"), null); | |
} |
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 cluster = require("cluster"); | |
const os = require("os"); | |
const PORT = process.env.PORT || 3001; | |
// Replace with your logger | |
const logger = console; | |
// If the current is master, create the fork for all the cpus |
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 PORT = process.env.PORT || 3001; | |
// Replace with your logger | |
const logger = 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
const axios = require("axios"); | |
const Agent = require("agentkeepalive"); | |
const CircuitBreaker = require("opossum"); | |
// Replace with your configs | |
const TIMEOUT_DEFAULT = 2500; | |
const MAX_SOCKETS = 100; | |
const MAX_FREE_SOCKET = 10; | |
const TIME_OUT_KEEP_ALIVE = 60000; | |
const FREE_SOCKET_TIMEOUT = 30000; |
NewerOlder