├── tslint.json ├── src ├── controller │ └── home.controller.ts ├── app.ts └── express.router.ts ├── package.json ├── README.md ├── .gitignore └── tsconfig.json /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": {}, 5 | "rules": { 6 | "quotemark": [true, "single"] 7 | }, 8 | "rulesDirectory": [] 9 | } 10 | -------------------------------------------------------------------------------- /src/controller/home.controller.ts: -------------------------------------------------------------------------------- 1 | import { NextFunction, Request, Response } from 'express'; 2 | 3 | export default class HomeController { 4 | public static getDefault(req: Request, res: Response, next: NextFunction) { 5 | res.send('Hello World!'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/app.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from 'dotenv'; 2 | import express from 'express'; 3 | import ExpressRotuer from './express.router'; 4 | 5 | dotenv.config(); 6 | 7 | const app = express(); 8 | const expressRoutes = new ExpressRotuer(app); 9 | expressRoutes.init(); 10 | 11 | app.listen(process.env.PORT, () => { 12 | console.log(`Express server app listening on port ${process.env.PORT}!`); 13 | }); 14 | -------------------------------------------------------------------------------- /src/express.router.ts: -------------------------------------------------------------------------------- 1 | import { Express, NextFunction, Request, Response, Router } from 'express'; 2 | import HomeController from './controller/home.controller'; 3 | 4 | export default class ExpressRouter { 5 | public router: Router; 6 | private app: Express; 7 | 8 | constructor(app: Express) { 9 | this.router = Router(); 10 | this.app = app; 11 | } 12 | 13 | public init(): void { 14 | this.router.get('/', HomeController.getDefault); 15 | this.app.use('/', this.router); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimum-nodejs-typescript-express", 3 | "version": "1.0.0", 4 | "description": "A minimum typescript,nodejs and express application", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "tsc && node dist/app.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/dotnetjalps/minimum-nodejs-typescript-express.git" 13 | }, 14 | "keywords": [ 15 | "typescript", 16 | "nodejs", 17 | "express" 18 | ], 19 | "devDependencies": { 20 | "@types/dotenv": "^4.0.2", 21 | "@types/express": "*", 22 | "@types/node": "*", 23 | "typescript": "*" 24 | }, 25 | "dependencies": { 26 | "dotenv": "^5.0.1", 27 | "express": "4.16.2" 28 | }, 29 | "author": "Jalpesh Vadgama", 30 | "license": "MIT", 31 | "bugs": { 32 | "url": "https://github.com/dotnetjalps/minimum-nodejs-typescript-express/issues" 33 | }, 34 | "homepage": "https://github.com/dotnetjalps/minimum-nodejs-typescript-express#readme" 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A minimal web application structure with technologies like node.js, typescript, express 2 | 3 | This project is created to help people who wants to start creating application with the TypeScript, Node.js and Express. 4 | 5 | ## How to run this project: 6 | 7 | To run this project first you need to run following command 8 | 9 | ```sh 10 | npm install <= install all the npm Dependencies 11 | npm start <= It will run project on port 8000. 12 | ``` 13 | 14 | ## Directory strcture of project: 15 | 16 | * app.ts - Typescript file for creating express application class and where we have initialized the application. 17 | * routes.ts - Typescript files for creating all the routes under Init() Method. 18 | * package.json - Contains all the packages and dev dependencies required for this application. You can add more as your requirement.. 19 | * tsconfig.json - Where all the typescript configuration is there and we converting typescript into ES5.. 20 | * Controller Folder - Contains all the classes for the controller of the express application. 21 | * tsconfig.json - Contains all the rules for TypeScript linting. 22 | 23 | ## License 24 | 25 | MIT 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node,visualstudiocode 3 | # Build directory 4 | dist 5 | 6 | ### Node ### 7 | # Logs 8 | logs 9 | *.log 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Runtime data 15 | pids 16 | *.pid 17 | *.seed 18 | *.pid.lock 19 | 20 | # Directory for instrumented libs generated by jscoverage/JSCover 21 | lib-cov 22 | 23 | # Coverage directory used by tools like istanbul 24 | coverage 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (http://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Typescript v1 declaration files 46 | typings/ 47 | 48 | # Optional npm cache directory 49 | .npm 50 | 51 | # Optional eslint cache 52 | .eslintcache 53 | 54 | # Optional REPL history 55 | .node_repl_history 56 | 57 | # Output of 'npm pack' 58 | *.tgz 59 | 60 | # Yarn Integrity file 61 | .yarn-integrity 62 | 63 | # dotenv environment variables file 64 | .env 65 | 66 | 67 | ### VisualStudioCode ### 68 | .vscode/* 69 | !.vscode/settings.json 70 | !.vscode/tasks.json 71 | !.vscode/launch.json 72 | !.vscode/extensions.json 73 | .history 74 | 75 | 76 | # End of https://www.gitignore.io/api/node,visualstudiocode 77 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation. */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 12 | // "outFile": "./", /* Concatenate and emit output to single file. */ 13 | "outDir": "./dist", /* Redirect output structure to the directory. */ 14 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 15 | // "removeComments": true, /* Do not emit comments to output. */ 16 | // "noEmit": true, /* Do not emit outputs. */ 17 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 18 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 19 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 20 | 21 | /* Strict Type-Checking Options */ 22 | "strict": true, /* Enable all strict type-checking options. */ 23 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 24 | // "strictNullChecks": true, /* Enable strict null checks. */ 25 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 26 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 27 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 28 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 29 | 30 | /* Additional Checks */ 31 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 32 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 33 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 34 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 35 | 36 | /* Module Resolution Options */ 37 | "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 38 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 39 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 40 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 41 | // "typeRoots": [], /* List of folders to include type definitions from. */ 42 | // "types": [], /* Type declaration files to be included in compilation. */ 43 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 44 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 45 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 46 | 47 | /* Source Map Options */ 48 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 49 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 50 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 51 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 52 | 53 | /* Experimental Options */ 54 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 55 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 56 | }, 57 | "include": [ 58 | "src/**/*.ts" 59 | ], 60 | "exclude": [ 61 | "node_modules" 62 | ] 63 | } --------------------------------------------------------------------------------