Skip to content

Instantly share code, notes, and snippets.

View ganeshkbhat's full-sized avatar

Krishnamurthy G B ganeshkbhat

View GitHub Profile
@ganeshkbhat
ganeshkbhat / object-extending.js
Last active November 30, 2018 08:54
Object properties Inheritance
function defaultStrFns(someStr) {
let arr;
function splitIntoArray() {
arr = someStr.split('');
return arr;
}
function concatFromArray() {
return arr.join('');
}
@ganeshkbhat
ganeshkbhat / object-extending.js
Last active November 30, 2018 08:53
Object properties Inheritance using prescribed method
function DefaultStrFns(someStr) {
let arr;
this.splitIntoArray = function() {
arr = someStr.split('');
return arr;
}
this.concatFromArray = function() {
return arr.join('');
}
@ganeshkbhat
ganeshkbhat / expressjs-before-after-middleware-implementation-after-sending-response-using-send-function.js
Created November 26, 2018 12:11
Expressjs - Before after middleware implementation after sending response using send function
const express = require('express');
const app = express();
const beforeMiddleware = function(req, res, next) {
console.log('Before middleware triggered');
next();
}
const responseHandler = function(req, res, next) {
console.log('Response Action implementation triggered with response instead of send');
@ganeshkbhat
ganeshkbhat / expressjs-normal-middleware implementation.js
Created November 26, 2018 12:06
Expressjs normal middleware implementation
const express = require('express');
const app = express();
const beforeMiddleware = function(req, res, next) {
console.log('Before middleware triggered');
next();
}
const responseHandler = function(req, res, next) {
console.log('Response Action implementation triggered with response instead of send');
@ganeshkbhat
ganeshkbhat / expressjs-before-after-middleware-implementation-after-sending-response
Created November 26, 2018 12:03
ExpressJS before after middleware implementation after sending response
const express = require('express');
const app = express();
const beforeMiddleware = function(req, res, next) {
console.log('Before middleware triggered');
next();
}
const responseHandler = function(req, res, next) {
console.log('Response Action implementation triggered with response instead of send');
@ganeshkbhat
ganeshkbhat / expressjs-before-after-middleware-implement
Created November 26, 2018 10:47
expressjs-before-after-middleware-implement
const express = require('express');
const app = express();
const beforeAfterInjection = function(req, res, next) {
res.response = function (obj) {
req.res = obj;
}
next();
}
@ganeshkbhat
ganeshkbhat / index.pug
Created October 4, 2018 06:14
ExpressJS Series: Simple
html
head
title= title
body
h1= status
@ganeshkbhat
ganeshkbhat / expressjs-template-engine-snippet.js
Last active October 4, 2018 06:15
ExpressJS Series: Addig a Template engine and usage
/* OTHER CODES */
// Set TEMPLATING Engine views folder
app.set('views', './views');
// Setting Pug as Templating engine
app.set('view engine', 'pug');
// Sends response from the template views/index
// Data of object {status:'running'} is provided/injected to the template and ...
@ganeshkbhat
ganeshkbhat / expressjs-response-serving-snippet.js
Last active October 4, 2018 06:31
ExpressJS Series: Serving response
// Sends response as JSON
app.get("/", function(req, res) {
res.status(200)
.send({status:'running'});
});
// Sends response as XML using any XML2JS convertor
const xml2js = require('xml2js');
app.get("/", function(req, res) {
res.status(200)
@ganeshkbhat
ganeshkbhat / expressjs-serving-static-file.snippet.js
Last active October 4, 2018 05:48
ExpressJS Series: Serving static ffile
const path = require('path');
/* ALL OTHER CODE */
// Serves index.html from the public folder when ...
// ... the client requests http://127.0.0.1:9001/
app.get("/", function(req, res) {
res.status(200)
.sendFile(path.join(__dirname, 'public', 'index.html'));
});