Skip to content

Instantly share code, notes, and snippets.

View ganeshkbhat's full-sized avatar

Krishnamurthy G B ganeshkbhat

View GitHub Profile
@ganeshkbhat
ganeshkbhat / gist:911b90a3b7d150d5bb59fc93eeabfa0e
Created February 2, 2024 06:25
after-middleware alternative
// after-middleware alternative - 2
const express = require('express');
const app = express();
const beforeMiddleware = function(req, res, next) {
console.log('Before middleware triggered');
next();
}
@ganeshkbhat
ganeshkbhat / fast-prime.js
Last active November 25, 2022 08:07
Calculate, work with primes or check primes in a very fast way possible: fast-prime.js
//
// SPECIAL LICENSE - PROPRIETARY LICENSE AGREEMENT ONLY
//
// https://github.com/ganeshkbhat/fastprimenumbers
//
/*
PROPRIETARY LICENSE AGREEMENT ONLY
Use for your opensource projects only. If you use it or modify it for your project please spend 2 minutes of your time crediting me
by letting me know by either sending me an email, or logging an issue with subject heading `[User]`, or `star` my project. But
@ganeshkbhat
ganeshkbhat / isESCode.cjs
Last active October 30, 2022 02:51
Find if a code is a ESM Module or a CommonJS Script or Module
const checkEsm = import("check-esm");
let isesm = checkEsm._isESCode("./isESCode.mjs");
console.log(isesm);
@ganeshkbhat
ganeshkbhat / regex-es6-imports.js
Created October 26, 2022 16:47 — forked from manekinekko/regex-es6-imports.js
A regular Expression to parse ECMAScript6 import syntax
let regex = `import
(?:
["'\s]*
([\w*{}\n, ]+)
from\s*
)?
["'\s]*
([@\w/_-]+)
["'\s]*
;?
@ganeshkbhat
ganeshkbhat / expressjs.api.config.js
Last active September 19, 2022 07:31
ExpressJS: API Template for getter from Database
/**
* Route Template: Config
* Path: ./expressjs.api.config.js
*/
var config = {
"pathRoute": "/main",
"dbConfig": {
"path": "mongodb://localhost:27017/test",
"conf": {
"useNewUrlParser": true,
@ganeshkbhat
ganeshkbhat / express.api.routes.js
Last active September 19, 2022 05:25
Expressjs: API Template Gulp Automation
/**
* ExpressJS Template Based Routes
Path: ./
*/
const path = require('path');
const fs = require('fs');
var app = require("express");
var normalizedPath = require("path").join(__dirname, "routes");
async function requireFiles(d, r = false, cb = (f) => { app.use(require(path.join(f, "index.js"))); }) {
@ganeshkbhat
ganeshkbhat / expressjs.a.route.template.js
Last active September 19, 2022 03:58
Expressjs: Config based Template
/**
* ExpressJS Template Based Routes
Path: ./
*/
var app = require("express");
const mainRoute = require("./templates/main.route.template");
app.use(mainRoute);
app.all("*", function(req, res, next) {
res.send("Hello World Route Present");
@ganeshkbhat
ganeshkbhat / expressjs.template.js
Last active September 19, 2022 02:40
ExpressJS: API Template
var app = require("express");
const mainRoute = require("./main.route")
app.use(mainRoute);
app.all("*", function(req, res, next) {
res.send("Hello World Route Present");
})
app.listen(8000, function() {
@ganeshkbhat
ganeshkbhat / middlewares.js
Created May 10, 2022 11:22
middlewaretemplates
function someMiddlewareName(req, res, next) {
console.log("Simple middleware Template");
next();
}
module.exports = someMiddlewareName
@ganeshkbhat
ganeshkbhat / config.json
Last active May 10, 2022 11:30
Automated Templatized Handlers
{
"host": "127.0.0.1",
"port": 11010,
"static": [
{
"path": "/web/path",
"folderpath": "/path/to/folder"
},
{
"folderpath": "/path/to/folder"