Skip to content

Instantly share code, notes, and snippets.

View AhmedCommando's full-sized avatar
:octocat:
Having Fun

AhmedCommando

:octocat:
Having Fun
View GitHub Profile
@AhmedCommando
AhmedCommando / tsconfig.json
Created July 5, 2019 20:35
tsconfig development mode
{
"compilerOptions": {
"module": "es6",
"noImplicitAny": true,
"target": "es5",
"outDir": "./build/",
"sourceMap": true,
"allowJs": true
},
"include": [
@AhmedCommando
AhmedCommando / tsconfig.prod.json
Created July 5, 2019 20:50
tsconfig production mode
{
"extends": "./tsconfig",
"compilerOptions": {
"sourceMap": false
}
}
@AhmedCommando
AhmedCommando / tslint.json
Created July 5, 2019 20:57
tslint for node with typescript
{
"defaultSeverity": "warning",
"project": "./tsconfig.json",
"extends": [
"tslint-eslint-rules"
],
"rulesDirectory": [
"node_modules/codelyzer",
"node_modules/tslint-origin-ordered-imports-rule/dist",
"node_modules/tslint-consistent-codestyle/rules",
@AhmedCommando
AhmedCommando / webpack.config.js
Created July 5, 2019 21:21
webpack configuration handles prod and dev config
const path = require('path');
// this package handles all the external packages
const nodeExternals = require('webpack-node-externals');
// help running shell commands with webpack before and after the build process
const WebpackShellPlugin = require('webpack-shell-plugin');
// used to do the typechecking in a seperate process so the transpiling will be handled only by tsloader.
// speed up compilation of code
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const {
@AhmedCommando
AhmedCommando / www.ts
Created July 5, 2019 21:30
www http server file
import * as http from 'http';
import logger from '../utils/winston-logger';
import App from '../index';
const server = http.createServer(App);
const normalizePort = (val: number|string): number|string|boolean => {
const normolizedPort = (typeof val === 'string') ? parseInt(val, 10) : val;
if (isNaN(normolizedPort)) {
@AhmedCommando
AhmedCommando / index.ts
Created July 5, 2019 21:32
App entry contains express, middleware, routes and controller calls
import * as bodyParser from 'body-parser';
import * as express from 'express';
// Creates and configures an ExpressJS web server.
class App {
// ref to Express instance
express: express.Application;
// Run configuration methods on the Express instance.
constructor() {
@AhmedCommando
AhmedCommando / package.json
Last active July 5, 2019 21:43
package.json scripts without testing
"scripts": {
"_comment_" : "clean our build folder and all logs",
"clean": "rimraf ./build/* && rimraf ./logs/*",
"_comment_" : "lint all source code",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"_comment_" : "build will clean, lint then will call webpack with watch enabled to check and transpile",
"build": "yarn clean && yarn lint && webpack --watch",
"_comment_" : "start the build in development mode",
"start:dev": "NODE_ENV=development yarn build",
"_comment_" : "will be called by webpack when build is done to run pm2 with our development config",
@AhmedCommando
AhmedCommando / pm2.config.js
Created July 5, 2019 21:50
contains common pm2 configuration, will be exported and used by the development config and the production config
module.exports = {
name: "api-rest",
script: 'build/main.bundle.js',
watch: true,
ignore_watch: ["node_modules"],
// new feature; increase restart delay each time after every crash or non reachable db per example
exp_backoff_restart_delay: 100,
//combine multiple err/out logs in one file for each
combine_logs: true,
//calls combine logs
@AhmedCommando
AhmedCommando / pm2-dev-process.config.js
Created July 5, 2019 21:53
pm2 ecosystem file for development environment
module.exports = {
apps: [
{
// we load the common config
...require('./pm2.config'),
// we set environment variables
env: {
"PORT": 3000,
"NODE_ENV": "development"
}
@AhmedCommando
AhmedCommando / pm2-prod-process.config.js
Created July 5, 2019 22:01
pm2 ecosystem file for production mode
// cluster mode for production env
module.exports = {
apps: [
{
...require('./pm2.config'),
instances: 2, // can be max or any number of processes the cpu can handle
exec_mode: "cluster",
env: {
"PORT": 8080,
"NODE_ENV": "production"