Skip to content

Instantly share code, notes, and snippets.

View artemis15's full-sized avatar
Technology Over a Cup of Coffee

Akash Rajput artemis15

Technology Over a Cup of Coffee
View GitHub Profile
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
xml2js = require('xml2js')
},{"xml2js":51}],2:[function(require,module,exports){
'use strict';
var keys = require('object-keys');
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
var toStr = Object.prototype.toString;
@artemis15
artemis15 / prom-client_pm2_cluster.js
Created August 27, 2021 11:48 — forked from yekver/prom-client_pm2_cluster.js
Instead of `cluster` module there is no direct access to the master process in `pm2`. To return metrics for the whole cluster you can do IPC calls from the active instance to the rest of them and wait while all their locally collected metrics will be sent. Finally you have to aggregate all received metrics.
const prom = require('prom-client');
const pm2 = require('pm2');
let pm2Bus;
const REQ_TOPIC = 'get_prom_register';
function pm2exec(cmd, ...args) {
return new Promise((resolve, reject) => {
pm2[cmd](...args, (err, resp) => (err ? reject(err) : resolve(resp)));
@artemis15
artemis15 / prom-client_pm2_cluster.js
Created August 27, 2021 11:48 — forked from yekver/prom-client_pm2_cluster.js
Instead of `cluster` module there is no direct access to the master process in `pm2`. To return metrics for the whole cluster you can do IPC calls from the active instance to the rest of them and wait while all their locally collected metrics will be sent. Finally you have to aggregate all received metrics.
const prom = require('prom-client');
const pm2 = require('pm2');
let pm2Bus;
const REQ_TOPIC = 'get_prom_register';
function pm2exec(cmd, ...args) {
return new Promise((resolve, reject) => {
pm2[cmd](...args, (err, resp) => (err ? reject(err) : resolve(resp)));
@artemis15
artemis15 / System Design.md
Created September 24, 2020 06:58 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@artemis15
artemis15 / auth.js
Created October 7, 2019 18:42
Auth js services file
const express = require('express');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const {validationResult} = require('express-validator/check');
const config = require('../../configs/config/config');
const userModel = require('../../models/user');
const register = async(req,res,next) => {
let errors = validationResult(req);
@artemis15
artemis15 / authgaurd.js
Created October 7, 2019 18:29
Authgaurd with JWT
const express = require('express');
const jwt = require('jsonwebtoken');
const config = require('../configs/config/config');
const authClientToken = async(req,res,next)=>{
let token = req.headers['x-access-token'];
if(!token)
{
return res.status(401).json({
'errors' : [{
@artemis15
artemis15 / validation.js
Created October 7, 2019 18:24
JWT validation file foe middleware
const {body} = require('express-validator/check');
const validateRegistrationBody = () => {
return [
body('name')
.exists()
.withMessage('name field is required')
.isLength({min:3})
.withMessage('name must be greater than 3 letters'),
body('email').exists()
.withMessage('email field is required')
@artemis15
artemis15 / user.js
Created October 7, 2019 18:15
Model for user schema JWT
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
let userSchema = new Schema(
{
name : {
type:String,
required:[true,'Name is required']
},
email : {
@artemis15
artemis15 / app.js
Created October 7, 2019 18:09
App.js with JWT
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const expressValidator = require('express-validator');
let routes = require("../routes/routes");
let server = express();
let create = (config, db) => {
server.set("env", config.env);
server.set("port", config.port);
@artemis15
artemis15 / lcoal.js
Created October 2, 2019 17:40
local.js file with JWT project
let localConfig = {
hostname: 'localhost',
port: 3000,
secret : '123secret321',
};
module.exports = localConfig;