Last active
September 19, 2022 03:58
-
-
Save ganeshkbhat/73489e842f49317aa1ca6f59287bca89 to your computer and use it in GitHub Desktop.
Expressjs: Config based Template
This file contains hidden or 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
/** | |
* 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"); | |
}) | |
app.listen(8000, function() { | |
console.log("Server started at 8000"); | |
}); |
This file contains hidden or 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
/** | |
* Route Template: | |
* Path: ./templates/expressjs.b.route.template.js | |
*/ | |
var app = require("express"); | |
var config = require("./expressjs.config.template); | |
var allRequest = require("./expressjs.all.template"); | |
var getRequest = require("./expressjs.get.template"); | |
var postRequest = require("./expressjs.post.template"); | |
var putRequest = require("./expressjs.put.template"); | |
var patchRequest = require("./expressjs.patch.template"); | |
var deleteRequest = require("./expressjs.delete.template"); | |
var optionsRequest = require("./expressjs.options.template"); | |
app.route(config.pathRoute) | |
.all(allRequest) | |
.get(getRequest) | |
.put(postRequest) | |
.post(putRequest) | |
.patch(patchRequest) | |
.delete(deleteRequest) | |
.options(optionsRequest); | |
module.exports = app; |
This file contains hidden or 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
/** | |
* Route Template: Config | |
* Path: ./templates/expressjs.b.route.template.js | |
*/ | |
var config = { | |
"pathRoute": "/main", | |
"dbConfig": { | |
"path": "xyzdb://user:pass@ipaddress:port" | |
}, | |
"someOtherConfig": "" | |
}; | |
module.exports = config; |
This file contains hidden or 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
/** | |
* Route Template: All | |
* Path: ./templates/expressjs.b.route.template.js | |
*/ | |
function allRequest(req, res, next) { | |
res.send('Hello World All request!'); | |
} |
This file contains hidden or 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
/** | |
* Route Template: Delete | |
* Path: ./templates/expressjs.route.delete.template.js | |
*/ | |
function deleteRequest(req, res, next) { | |
res.send('Hello World Delete request!'); | |
} |
This file contains hidden or 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
/** | |
* Route Template: Get | |
* Path: ./template/expressjs.route.get.template.js | |
*/ | |
function getRequest(req, res, next) { | |
res.send('Hello World Get request!'); | |
} |
This file contains hidden or 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
/** | |
* Route Template: Options | |
* Path: ./templates/expressjs.route.options.template.js | |
*/ | |
function optionsRequest(req, res, next) { | |
res.send('Hello World Options request!'); | |
} |
This file contains hidden or 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
/** | |
* Route Template: Patch | |
* Path: ./templates/expressjs.route.patch.template.js | |
*/ | |
function patchRequest(req, res, next) { | |
res.send('Hello World Patch request!'); | |
} |
This file contains hidden or 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
/** | |
* Route Template: Post | |
* Path: ./templates/expressjs.route.post.template.js | |
*/ | |
function postRequest(req, res, next) { | |
res.send('Hello World Post request!'); | |
} |
This file contains hidden or 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
/** | |
* Route Template: Put | |
* Path: ./templates/expressjs.route.put.template.js | |
*/ | |
function putRequest(req, res, next) { | |
res.send('Hello World Put request!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment