Repository: kelyvin/express-env-example
Branch: master
Commit: d519a3542f41
Files: 23
Total size: 7.8 KB
Directory structure:
gitextract_7dxvdjfg/
├── .gitignore
├── LICENSE
├── README.md
├── app/
│ └── views/
│ ├── error/
│ │ └── index.hbs
│ ├── home/
│ │ ├── index.hbs
│ │ └── info.hbs
│ └── layouts/
│ └── default.hbs
├── configs/
│ ├── index.js
│ └── local.js
├── index.js
├── package.json
└── server/
├── controllers/
│ ├── apis/
│ │ ├── animals/
│ │ │ └── index.js
│ │ └── dogs/
│ │ └── index.js
│ ├── error.js
│ └── home.js
├── index.js
├── routes/
│ ├── apis/
│ │ ├── index.js
│ │ ├── v1/
│ │ │ └── index.js
│ │ └── v2/
│ │ └── index.js
│ ├── error.js
│ ├── home.js
│ └── index.js
└── services/
└── dogs/
└── index.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# OSX
.DS_Store
# Logs
logs
*.log
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules/
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2017 Kelvin Nguyen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
# Express Env Example
This is an express environment example that I wrote to demonstrate modular Express routing patterns. This environment enables easy extensibility, scalability, and proper software design practices.
**03/13/2018 Update**: An improved/advanced version of this architecture will be uploaded in the near future, be on the lookout.
## Running
To start and run the project/server, simply run the following command in your root directory:
```
npm start
```
## Sample endpoints
### Views
- `/` - Default route that redirects to the home page
- `/home` - Render the home page sample
- `/home/info` - Render the home page sample
- `/error` - Render the error page sample
### API
- `/api/v1/dogs` - Get all dogs
- `/api/v1/dogs/:id` - Get a dog with the specified id
- `/api/v2/animals/dogs` - Get all dogs
- `/api/v2/animals/dogs/:id` - Get a dog with the specified id
================================================
FILE: app/views/error/index.hbs
================================================
<h1>Oh shoot, looks like you ran into an error.</h1>
<h2>This is probably your fault...</h2>
================================================
FILE: app/views/home/index.hbs
================================================
<h1>Welcome to this express environment sample by Kelvin!</h1>
================================================
FILE: app/views/home/info.hbs
================================================
<h1>You can follow more of Kelvin's projects on his blog: <a href="https://www.caffeinecoding.com">Caffeine Coding!</a></h1>
================================================
FILE: app/views/layouts/default.hbs
================================================
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{{body}}}
</body>
</html>
================================================
FILE: configs/index.js
================================================
'use strict';
const
_ = require('lodash'),
env = process.env.NODE_ENV || 'local',
envConfig = require('./' + env);
let defaultConfig = {
env: env
};
module.exports = _.merge(defaultConfig, envConfig);
================================================
FILE: configs/local.js
================================================
'use strict';
let localConfig = {
hostname: 'localhost',
port: 3000,
viewDir: './app/views'
};
module.exports = localConfig;
================================================
FILE: index.js
================================================
'use strict';
const
server = require('./server')(),
config = require('./configs');
server.create(config);
server.start();
================================================
FILE: package.json
================================================
{
"name": "express-env-sample",
"version": "1.0.0",
"description": "App example of express environment",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"engines": {
"node": "^4.2.0"
},
"author": "Kelvin Nguyen",
"dependencies": {
"body-parser": "^1.16.0",
"express": "^4.14.1",
"express-handlebars": "^3.0.0",
"lodash": "^4.17.4"
}
}
================================================
FILE: server/controllers/apis/animals/index.js
================================================
'use strict';
const
express = require('express'),
dogController = require('../dogs');
let router = express.Router();
router.use('/dogs', dogController);
module.exports = router;
================================================
FILE: server/controllers/apis/dogs/index.js
================================================
'use strict';
const
express = require('express'),
dogService = require('../../../services/dogs');
let router = express.Router();
router.get('/', dogService.getDogs);
router.get('/:id', dogService.getDogWithId);
module.exports = router;
================================================
FILE: server/controllers/error.js
================================================
'use strict';
function index (req, res) {
res.render('error/index', {
title: 'Error'
});
}
module.exports = {
index: index
};
================================================
FILE: server/controllers/home.js
================================================
'use strict';
function index (req, res) {
res.render('home/index', {
title: 'Home'
});
}
function info (req, res) {
res.render('home/info', {
title: 'More info'
});
}
module.exports = {
index: index,
info: info
};
================================================
FILE: server/index.js
================================================
'use strict';
const
express = require('express'),
expressHandlebars = require('express-handlebars'),
bodyParser = require('body-parser');
module.exports = function() {
let server = express(),
create,
start;
create = function(config) {
let routes = require('./routes');
// Server settings
server.set('env', config.env);
server.set('port', config.port);
server.set('hostname', config.hostname);
server.set('viewDir', config.viewDir);
// Returns middleware that parses json
server.use(bodyParser.json());
// Setup view engine
server.engine('.hbs', expressHandlebars({
defaultLayout: 'default',
layoutsDir: config.viewDir + '/layouts',
extname: '.hbs'
}));
server.set('views', server.get('viewDir'));
server.set('view engine', '.hbs');
// Set up routes
routes.init(server);
};
start = function() {
let hostname = server.get('hostname'),
port = server.get('port');
server.listen(port, function () {
console.log('Express server listening on - http://' + hostname + ':' + port);
});
};
return {
create: create,
start: start
};
};
================================================
FILE: server/routes/apis/index.js
================================================
'use strict';
const
express = require('express'),
v1ApiController = require('./v1'),
v2ApiController = require('./v2');
let router = express.Router();
router.use('/v1', v1ApiController);
router.use('/v2', v2ApiController);
module.exports = router;
================================================
FILE: server/routes/apis/v1/index.js
================================================
'use strict';
const
express = require('express'),
dogsController = require('../../../controllers/apis/dogs');
let router = express.Router();
router.use('/dogs', dogsController);
module.exports = router;
================================================
FILE: server/routes/apis/v2/index.js
================================================
'use strict';
const
express = require('express'),
animalsController = require('../../../controllers/apis/animals');
let router = express.Router();
router.use('/animals', animalsController);
module.exports = router;
================================================
FILE: server/routes/error.js
================================================
'use strict';
const
express = require('express'),
errorController = require('../controllers/error');
let router = express.Router();
router.get('/', errorController.index);
module.exports = router;
================================================
FILE: server/routes/home.js
================================================
'use strict';
const
express = require('express'),
homeController = require('../controllers/home');
let router = express.Router();
router.get('/', homeController.index);
router.get('/info', homeController.info);
module.exports = router;
================================================
FILE: server/routes/index.js
================================================
'use strict';
const
apiRoute = require('./apis'),
homeRoute = require('./home'),
errorRoute = require('./error');
function init(server) {
server.get('*', function (req, res, next) {
console.log('Request was made to: ' + req.originalUrl);
return next();
});
server.get('/', function (req, res) {
res.redirect('/home');
});
server.use('/api', apiRoute);
server.use('/home', homeRoute);
server.use('/error', errorRoute);
}
module.exports = {
init: init
};
================================================
FILE: server/services/dogs/index.js
================================================
'use strict';
const
dogs = [{
id: 1,
name: 'Corgi',
origin: 'Wales',
breeds: [
'Pembroke',
'Cardigan'
]
}, {
id: 2,
name: 'Husky',
breeds: [
'Alaskan',
'Siberian',
'Labrador',
'Sakhalin'
]
}];
function getDogs(req, res) {
res.json(dogs);
}
function getDogWithId(req, res) {
let id = req.params.id || 0,
result = {};
for (let i = 0; i < dogs.length; i++) {
if (dogs[i].id == id) {
result = dogs[i];
break;
}
}
res.json(result);
}
module.exports = {
getDogs: getDogs,
getDogWithId: getDogWithId
};
gitextract_7dxvdjfg/
├── .gitignore
├── LICENSE
├── README.md
├── app/
│ └── views/
│ ├── error/
│ │ └── index.hbs
│ ├── home/
│ │ ├── index.hbs
│ │ └── info.hbs
│ └── layouts/
│ └── default.hbs
├── configs/
│ ├── index.js
│ └── local.js
├── index.js
├── package.json
└── server/
├── controllers/
│ ├── apis/
│ │ ├── animals/
│ │ │ └── index.js
│ │ └── dogs/
│ │ └── index.js
│ ├── error.js
│ └── home.js
├── index.js
├── routes/
│ ├── apis/
│ │ ├── index.js
│ │ ├── v1/
│ │ │ └── index.js
│ │ └── v2/
│ │ └── index.js
│ ├── error.js
│ ├── home.js
│ └── index.js
└── services/
└── dogs/
└── index.js
SYMBOL INDEX (6 symbols across 4 files)
FILE: server/controllers/error.js
function index (line 3) | function index (req, res) {
FILE: server/controllers/home.js
function index (line 3) | function index (req, res) {
function info (line 9) | function info (req, res) {
FILE: server/routes/index.js
function init (line 8) | function init(server) {
FILE: server/services/dogs/index.js
function getDogs (line 24) | function getDogs(req, res) {
function getDogWithId (line 28) | function getDogWithId(req, res) {
Condensed preview — 23 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
{
"path": ".gitignore",
"chars": 165,
"preview": "# OSX\n.DS_Store\n\n# Logs\nlogs\n*.log\n\n# Dependency directory\n# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-"
},
{
"path": "LICENSE",
"chars": 1079,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2017 Kelvin Nguyen\n\nPermission is hereby granted, free of charge, to any person obt"
},
{
"path": "README.md",
"chars": 897,
"preview": "# Express Env Example\n\nThis is an express environment example that I wrote to demonstrate modular Express routing patter"
},
{
"path": "app/views/error/index.hbs",
"chars": 92,
"preview": "<h1>Oh shoot, looks like you ran into an error.</h1>\n<h2>This is probably your fault...</h2>"
},
{
"path": "app/views/home/index.hbs",
"chars": 62,
"preview": "<h1>Welcome to this express environment sample by Kelvin!</h1>"
},
{
"path": "app/views/home/info.hbs",
"chars": 124,
"preview": "<h1>You can follow more of Kelvin's projects on his blog: <a href=\"https://www.caffeinecoding.com\">Caffeine Coding!</a><"
},
{
"path": "app/views/layouts/default.hbs",
"chars": 105,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n <title>{{title}}</title>\n</head>\n<body>\n {{{body}}}\n</body>\n</html>\n"
},
{
"path": "configs/index.js",
"chars": 220,
"preview": "'use strict';\n\nconst\n _ = require('lodash'),\n env = process.env.NODE_ENV || 'local',\n envConfig = require('./' "
},
{
"path": "configs/local.js",
"chars": 139,
"preview": "'use strict';\n\nlet localConfig = {\n hostname: 'localhost',\n port: 3000,\n viewDir: './app/views'\n};\n\nmodule.expo"
},
{
"path": "index.js",
"chars": 131,
"preview": "'use strict';\n\nconst\n server = require('./server')(),\n config = require('./configs');\n\nserver.create(config);\nserv"
},
{
"path": "package.json",
"chars": 394,
"preview": "{\n \"name\": \"express-env-sample\",\n \"version\": \"1.0.0\",\n \"description\": \"App example of express environment\",\n \"main\":"
},
{
"path": "server/controllers/apis/animals/index.js",
"chars": 189,
"preview": "'use strict';\n\nconst\n express = require('express'),\n dogController = require('../dogs');\n\nlet router = express.Rou"
},
{
"path": "server/controllers/apis/dogs/index.js",
"chars": 247,
"preview": "'use strict';\n\nconst\n express = require('express'),\n dogService = require('../../../services/dogs');\n\nlet router ="
},
{
"path": "server/controllers/error.js",
"chars": 147,
"preview": "'use strict';\n\nfunction index (req, res) {\n res.render('error/index', {\n title: 'Error'\n });\n}\n\nmodule.expo"
},
{
"path": "server/controllers/home.js",
"chars": 256,
"preview": "'use strict';\n\nfunction index (req, res) {\n res.render('home/index', {\n title: 'Home'\n });\n}\n\nfunction info"
},
{
"path": "server/index.js",
"chars": 1309,
"preview": "'use strict';\n\nconst\n express = require('express'),\n expressHandlebars = require('express-handlebars'),\n bodyPa"
},
{
"path": "server/routes/apis/index.js",
"chars": 263,
"preview": "'use strict';\n\nconst\n express = require('express'),\n v1ApiController = require('./v1'),\n v2ApiController = requ"
},
{
"path": "server/routes/apis/v1/index.js",
"chars": 214,
"preview": "'use strict';\n\nconst\n express = require('express'),\n dogsController = require('../../../controllers/apis/dogs');\n\n"
},
{
"path": "server/routes/apis/v2/index.js",
"chars": 226,
"preview": "'use strict';\n\nconst\n express = require('express'),\n animalsController = require('../../../controllers/apis/animal"
},
{
"path": "server/routes/error.js",
"chars": 208,
"preview": "'use strict';\n\nconst\n express = require('express'),\n errorController = require('../controllers/error');\n\nlet route"
},
{
"path": "server/routes/home.js",
"chars": 247,
"preview": "'use strict';\n\nconst\n express = require('express'),\n homeController = require('../controllers/home');\n\nlet router "
},
{
"path": "server/routes/index.js",
"chars": 525,
"preview": "'use strict';\n\nconst\n apiRoute = require('./apis'),\n homeRoute = require('./home'),\n errorRoute = require('./er"
},
{
"path": "server/services/dogs/index.js",
"chars": 738,
"preview": "'use strict';\n\nconst\n dogs = [{\n id: 1,\n name: 'Corgi',\n origin: 'Wales',\n breeds: [\n "
}
]
About this extraction
This page contains the full source code of the kelyvin/express-env-example GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 23 files (7.8 KB), approximately 2.5k tokens, and a symbol index with 6 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.