Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
iradofurioso committed Sep 20, 2022
2 parents e811be7 + a47b300 commit cc2294f
Show file tree
Hide file tree
Showing 23 changed files with 301 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# General
cache/*
!cache/.gitkeep

# Uploaded files, storage files.
storage/*
!storage/.gitkeep

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
logs/*
!logs/.gitkeep

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -40,6 +50,11 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
package-lock.json
yarn.lock

# TypeScript
typechain

# TypeScript v1 declaration files
typings/
Expand Down Expand Up @@ -102,3 +117,10 @@ dist

# TernJS port file
.tern-port

# Stores VSCode WebStorm and other IDE development content
.vscode/
.vscode-test
.idea
.DS_Store
.directory
19 changes: 19 additions & 0 deletions LICENSE
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.
43 changes: 41 additions & 2 deletions README.md
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 added cache/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions jsconfig.json
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/*"]
}
}
}
6 changes: 6 additions & 0 deletions nodemon.json
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"
}
64 changes: 64 additions & 0 deletions package.json
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 added scripts/.gitkeep
Empty file.
Empty file added src/config/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions src/controllers/dummy/dummy.ts
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()
25 changes: 25 additions & 0 deletions src/index.ts
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 added src/middlewares/.gitkeep
Empty file.
Empty file added src/models/.gitkeep
Empty file.
Empty file added src/modules/.gitkeep
Empty file.
Empty file added src/resources/.gitkeep
Empty file.
Empty file added src/routes/.gitkeep
Empty file.
11 changes: 11 additions & 0 deletions src/routes/dummy.ts
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 added src/services/.gitkeep
Empty file.
Empty file added src/tests/.gitkeep
Empty file.
Empty file added src/types/.gitkeep
Empty file.
Empty file added src/utils/.gitkeep
Empty file.
61 changes: 61 additions & 0 deletions tsconfig.json
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"
]
}
22 changes: 22 additions & 0 deletions webpack.config.js
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')
}
}
}

0 comments on commit cc2294f

Please sign in to comment.