Skip to content

Instantly share code, notes, and snippets.

View tarusharora's full-sized avatar
🎯
Focusing

Tarush Arora tarusharora

🎯
Focusing
View GitHub Profile
@tarusharora
tarusharora / server.js
Created December 22, 2018 21:33
node-api-boilerplate
// import dependencies from npm
const Fastify = require('fastify');
const path = require('path');
const AutoLoad = require('fastify-autoload');
const uuidv4 = require('uuid/v4');
// create request ids
const createRequestId = () => uuidv4();
// create the server
@tarusharora
tarusharora / appSettings.json
Last active December 27, 2018 22:09
Simple App Settings file
{
"logSeverity": "info"
}
@tarusharora
tarusharora / configurationAdaptor.js
Created December 27, 2018 22:09
Configuration Adaptor
const nconf = require('nconf');
const _ = require('lodash');
const loadSettings = ({ appSettingsPath }) => new Promise((resolve, reject) => {
try {
if (_.isEmpty(appSettingsPath)) {
throw new Error('Configuration settings path is required.');
}
nconf.file({
file: appSettingsPath,
@tarusharora
tarusharora / app.js
Created December 28, 2018 22:59
App.js Basic
const nconf = require('nconf');
const server = require('./server');
const { loadSettings } = require('./config/configurationAdaptor');
const appSettingsPath = process.env.APP_SETTINGS_FILE_PATH;
loadSettings({ appSettingsPath })
.then(() => {
// TODO Connect to DB, if any.
@tarusharora
tarusharora / server.js
Last active December 28, 2018 23:02
Server file Part 2
// import dependencies from npm
const Fastify = require('fastify');
const path = require('path');
const AutoLoad = require('fastify-autoload');
const uuidv4 = require('uuid/v4');
// create request ids
const createRequestId = () => uuidv4();
const createServer = (options) => {
@tarusharora
tarusharora / appSettings.json
Created December 29, 2018 09:04
App settings part 2
{
"logSeverity": "info",
"app": {
"isEmailVerificationEnabled": false,
"emailTokenExpiryInSeconds": "7d",
"userPasswordRegex" : "^(?=.{6,})",
"userJwtExpiry" : "2d"
},
"url" : {
"self": "",
@tarusharora
tarusharora / root.js
Last active December 29, 2018 10:57
api/routes/root.js
// api/routes/root.js
module.exports = async function (fastify, opts) {
fastify.get('/', async function (request, reply) {
return { hello: "World" }
})
}
@tarusharora
tarusharora / server.js
Created December 29, 2018 12:03
Server with fastify autoload
// import dependencies from npm
const Fastify = require('fastify');
const path = require('path');
const AutoLoad = require('fastify-autoload');
const uuidv4 = require('uuid/v4');
// create request ids
const createRequestId = () => uuidv4();
const createServer = (options) => {
@tarusharora
tarusharora / launch.json
Created December 30, 2018 11:36
sampe VS Code debugging launch configuration
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
@tarusharora
tarusharora / httpClient.js
Created February 16, 2019 13:40
http client using request-promise-native
const request = require('request-promise-native');
const nconf = require('nconf');
const externalAPITimeout = nconf.get('app.externalAPITimeout');
const getRequest = ({url, options}) => request.get(url, {...options, timeout: externalAPITimeout, json:true});
module.exports = {
getRequest
}