-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
301 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2022 Iradofurioso Node Kickstarter | ||
|
||
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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,41 @@ | ||
# node-kickstarter | ||
A boilerplate for building production-ready RESTful APIs using Node.js. | ||
# NODE KICKSTARTER | ||
|
||
![ts](https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555) | ||
|
||
A boilerplate TypeScript project for building RESTful APIs using Node.js and Restify. By running a few commands, you | ||
will get a production-ready Node.js server installed and fully configured on your machine. | ||
The server comes with many built-in features. | ||
|
||
## Quick Start | ||
|
||
Run the following commands to get everything working: | ||
|
||
```bash | ||
npm i | ||
npm run build | ||
npm run start | ||
``` | ||
|
||
Check the scripts section in package.json to change the commands to fit your needs. | ||
|
||
## Project Structure | ||
|
||
``` | ||
src\ | ||
|--config\ # Environment variables and configuration related things | ||
|--controllers\ # Controller layer | ||
|--middlewares\ # Custom middlewares | ||
|--models\ # Database models (data layer) | ||
|--modules\ # In case the project is using modularized approach. | ||
|--resources\ # Special resources such as sol files for cryptocurrency. | ||
|--routes\ # Routes | ||
|--services\ # Business logic (service layer) | ||
|--tests\ # Test files. | ||
|--types\ # TypeScript custom types. | ||
|--utils\ # Utility classes and functions | ||
|--index.ts # App entry point | ||
``` | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@root": ["."], | ||
"@src/*": ["src/*"], | ||
"@config": ["src/config"], | ||
"@controllers/*": ["src/controllers/*"], | ||
"@middlewares/*": ["src/middlewares/*"], | ||
"@models/*": ["src/models/*"], | ||
"@modules/*": ["src/modules/*"], | ||
"@resources/*": ["src/resources/*"], | ||
"@routes/*": ["src/routes/*"], | ||
"@services/*": ["src/services/*"], | ||
"@tests/*": ["src/tests/*"], | ||
"@types/*": ["src/types/*"], | ||
"@utils/*": ["src/utils/*"] | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["src"], | ||
"ext": ".ts,.js", | ||
"ignore": [], | ||
"exec": "ts-node -r tsconfig-paths/register --files ./src/index.ts" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"name": "@iradofurioso/node-kickstarter", | ||
"version": "1.0.0", | ||
"description": "A boilerplate for building production-ready RESTful APIs using Node", | ||
"main": "index.js", | ||
"scripts": { | ||
"start-prod": "npm run build && node build/index.js", | ||
"start": "npx nodemon --watch src/ -e ts --ignore 'src/**/*.spec.ts' --exec 'npx tsc --project tsconfig.json --skipLibCheck && tsc-alias -p tsconfig.json -f && node --enable-source-maps ./dist/index.js server'", | ||
"format": "prettier --write --no-semi '**/*.ts'", | ||
"format-check": "prettier --no-semi --check '**/*.ts'", | ||
"build": "echo '⚙️ Kickstarting...' && rimraf ./dist/* && npx tsc --project tsconfig.json && npx tsc-alias -p tsconfig.json -f", | ||
"test": "echo \"❌ Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "Iradofurioso", | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^0.24.0", | ||
"bcryptjs": "^2.4.3", | ||
"dotenv": "^10.0.0", | ||
"jsonwebtoken": "^8.5.1", | ||
"restify": "^8.6.1", | ||
"tsconfig-paths": "^3.12.0", | ||
"yup": "^0.32.11" | ||
}, | ||
"devDependencies": { | ||
"@types/bcryptjs": "^2.4.2", | ||
"@types/chai": "^4.3.0", | ||
"@types/jsonwebtoken": "^8.5.9", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^17.0.5", | ||
"@types/restify": "^8.5.5", | ||
"@types/typescript": "^2.0.0", | ||
"chai": "^4.3.4", | ||
"nodemon": "^2.0.15", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"ts-generator": "^0.1.1", | ||
"ts-node": "^10.4.0", | ||
"tsc-alias": "^1.7.0", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.8.3" | ||
}, | ||
"_moduleAliases": { | ||
"@root": ".", | ||
"@src": "src", | ||
"@config": "src/config", | ||
"@controllers": "src/controllers", | ||
"@middlewares": "src/middlewares", | ||
"@models": "src/models", | ||
"@modules": "src/modules", | ||
"@resources": "src/resources", | ||
"@routes": "src/routes", | ||
"@services": "src/services", | ||
"@tests": "src/tests", | ||
"@types": "src/types", | ||
"@utils": "src/utils" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/iradofurioso/node-kickstarter.git" | ||
}, | ||
"homepage": "https://github.com/iradofurioso/node-kickstarter/blob/master/README.md" | ||
} |
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Next, Request, Response } from "restify" | ||
|
||
class DummyController { | ||
public async home(req: Request, res: Response, next: Next) { | ||
console.log('WORKING WORKING WORKING WORKING WORKING WORKING') | ||
return next() | ||
} | ||
} | ||
|
||
export default new DummyController() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createServer, Server, plugins } from "restify" | ||
import dummyRouter from "@routes/dummy" | ||
|
||
const initApp = async () => { | ||
const app: Server = createServer({ | ||
name: "com.github.node.kickstarter", | ||
version: "1.0.0", | ||
}) | ||
|
||
app.use(plugins.queryParser()) | ||
app.use(plugins.bodyParser()) | ||
dummyRouter(app) | ||
|
||
// Start server | ||
try { | ||
app.listen(5000, () => { | ||
console.info(`Server started at port: HTTP - ${5000}`) | ||
}) | ||
} catch (err) { | ||
console.error(`Server not started | ${err}`) | ||
process.exit(2) | ||
} | ||
} | ||
|
||
initApp() |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import DummyController from "@controllers/dummy/dummy" | ||
|
||
const dummyRouter = (server: any) => { | ||
server.get( | ||
"/home", | ||
[], | ||
DummyController.home | ||
) | ||
} | ||
|
||
export default dummyRouter |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
/* see: https://www.typescriptlang.org/tsconfig#lib */ | ||
|
||
"compilerOptions": { | ||
/* Language and Environment */ | ||
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
|
||
/* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
"lib": [ | ||
"es2021", | ||
], | ||
|
||
/* Modules */ | ||
"module": "commonjs", /* Specify what module code is generated: commonjs or esm */ | ||
"rootDir": "src", /* Specify the root folder within your source files. */ | ||
"resolveJsonModule": true, /* Enable importing .json files */ | ||
|
||
"sourceMap": true, /* Let the command Tsc generate source maps to find the issue in your code */ | ||
|
||
/* JavaScript Support */ | ||
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ | ||
|
||
/* Emit */ | ||
"outDir": "dist", /* Specify an output folder for all emitted files. */ | ||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ | ||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. Disallow inconsistently-cased references to the same file */ | ||
|
||
/* Type Checking */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ | ||
/* Completeness */ | ||
"skipLibCheck": true, /* Skip type checking all .d.ts files. */ | ||
"typeRoots": ["./node_modules/@types", "./src/types"], /* List of folders to include type definitions from. */ | ||
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */ | ||
|
||
|
||
|
||
/* Project Paths - change according to defined structure */ | ||
"paths": { | ||
// "~service/*": ["src/*"], | ||
"*": ["node_modules/*", "lib/types/*"], | ||
"@config/*": ["./src/config/*", "./dist/config/*"], | ||
"@controllers/*": ["./src/controllers/*", "./dist/controllers/*"], | ||
"@middlewares/*": ["./src/middlewares/*", "./dist/middlewares/*"], | ||
"@models/*": ["./src/models/*", "./dist/models/*"], | ||
"@modules/*": ["./src/modules/*", "./dist/modules/*"], | ||
"@resources/*": ["./src/resources/*", "./dist/resources/*"], | ||
"@types/*": ["./src/types/index", "./dist/types/index"], | ||
"@routes/*": ["./src/routes/*", "./dist/routes/*"], | ||
"@utils/*": ["./src/utils/*", "./dist/utils/*"], | ||
"@utils": ["./src/utils/index", "./dist/utils/index"] | ||
}, | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"include": [ | ||
"./src/**/*.tsx", | ||
"./src/**/*.ts" | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// webpack.config.js | ||
const path = require('path') | ||
|
||
module.exports = { | ||
resolve: { | ||
alias: { | ||
"@root": path.resolve(__dirname, '.'), | ||
"@src": path.resolve(__dirname, 'src'), | ||
"@config": path.resolve(__dirname, 'src/config'), | ||
"@controllers": path.resolve(__dirname, 'src/controllers'), | ||
"@middlewares": path.resolve(__dirname, 'src/middlewares'), | ||
"@models": path.resolve(__dirname, 'src/models'), | ||
"@modules": path.resolve(__dirname, 'src/modules'), | ||
"@resources": path.resolve(__dirname, 'src/resources'), | ||
"@routes": path.resolve(__dirname, 'src/routes'), | ||
"@services": path.resolve(__dirname, 'src/services'), | ||
"@tests": path.resolve(__dirname, 'src/tests'), | ||
"@types": path.resolve(__dirname, 'src/types'), | ||
"@utils": path.resolve(__dirname, 'src/utils') | ||
} | ||
} | ||
} |