Skip to content

Commit

Permalink
chore(app): initialized app
Browse files Browse the repository at this point in the history
  • Loading branch information
thepatrickniyo committed Mar 14, 2022
0 parents commit 01134c0
Show file tree
Hide file tree
Showing 21 changed files with 2,927 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"@typescript-eslint/eslint-plugin"
],
"extends": [
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "warn"
}
}
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

# Build
public/css/main.css

# Coverage reports
coverage

# API keys and secrets
.env

# Dependency directory
node_modules
bower_components

# Editors
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
dist/**/*

# ignore yarn.lock
yarn.lock
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"maty.vscode-mocha-sidebar"
]
}
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// 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 ts-node",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/index.ts"
],
"preLaunchTask": "tsc: build - tsconfig.json",
}
]
}
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"files.exclude": {
"**/node_modules": true
},
"javascript.referencesCodeLens.enabled": true,
"typescript.referencesCodeLens.enabled": true,
"typescript.implementationsCodeLens.enabled": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"debug.javascript.usePreview": false,
// maty.vscode-mocha-sidebar settings
"mocha.files.glob": "test/**/*.test.ts",
"mocha.requires": [
"ts-node/register",
"module-alias/register"
],
"mocha.coverage": {
"enable": false
}
}
27 changes: 27 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig-build.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "tsc: build - tsconfig-build.json"
},
{
"type": "npm",
"script": "test",
"group": {
"kind": "test",
"isDefault": true
},
"label": "npm: test",
"detail": "mocha",
}
]
}
163 changes: 163 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Boilerplate

A boilerplate for a node web api application. It's designed to work out-of-the-box.

## Why?

The JavaScript ecosystem is intimidating. There are numerous options for everything, each of which having a mountain of the write and wrong ways to use said options, and even more reasons why or why not to use said options, and yet even more still opinions on which tools to use with them. I'm all about the "lego" mentality, but at a certain point, I mean... Fuck! I don't want to have to sift through tabs and tabs of dox just to return `Hello, world` from my API.

So, here's this...

A boilerplate for a [Node.js®](https://nodejs.org/en/) backend api written in [TypeScript](https://www.typescriptlang.org/). It has [Mocha](https://mochajs.org/) for unit tests. If you follow the instructions, it should work out of the box for anyone... If it doesn't, please, log an issue, and it will be attended to.

## TL;DR

`git clone https://github.com/revrenlove/node-boilerplate`

`cd node-boilerplate`

`npm install`

`npm start`

`curl localhost:8080/api/greeter?name=Bill`

- Should return: `Hello, Bill!`

### Building

`npm run build`

### Testing

`npm test`

## Requirements

- [Node.js®](https://nodejs.org/en/)

### Recommended

- [Visual Studio Code](https://code.visualstudio.com/)

There are included vscode specific settings included to streamline things.

[See Below](#visual-studio-code).

#### Windows-specific

- [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)

Using WSL on Windows is just a smoother developer experience.

## Includes

- [TypeScript](https://www.typescriptlang.org/)

- [ESLint](https://eslint.org/)

- [typescript-ioc](https://github.com/thiagobustamante/typescript-ioc)

IoC container for typescript.

- [module-alias](https://github.com/ilearnio/module-alias)

Allows your transpiled code to actually make use of the `paths` section of your `tsconfig.json` file.

- [Mocha](https://mochajs.org/)

For testing.

- [Chai Assertion Library](https://www.chaijs.com/)

Assertion library.

## Config files

### `eslintrc.json`

Has all the rules/config for ESLint.

### `mocharc.jsonc`

Config settings for mocha when running it from the command line.

- `ts-node/register` - for compilation.

- `module-alias/register` - for path alias recognition.

### `package.json`

#### `scripts`

- `clean` - removes `dist` folder.

- `build` - runs `clean` and builds app.

- `start` - cleans, builds, and starts app.

- `test` - runs `mocha` with settings in `mocharc.jsonc`.

#### `_moduleAliases`

Needed for `module-alias` package. Should match keys in `paths` of `tsconfig.json` as such (note the lack of wildcard in `package.json`):

`package.json`

```json
{
// ...
"_moduleAliases": {
"@service": "dist/service"
// ...
}
// ...
}
```

`tsconfig.json`

```json
{
"compilerOptions": {
// ...
"paths": {
"@service/*": ["./src/service"]
// ...
}
// ...
}
}
```

### `tsconfig.json`

`include` key is for including any source files that you want VSCode to recognize.

#### `tsconfig-build.json`

Used only for build to exclude the `test` folder in compilation.

## Visual Studio Code

After cloning and prior to opening in Visual Studio Code, go ahead and run the install and build commands to prevent it barking at you.

`npm install`

`npm run build`

Once you have the folder open in Visual Studio Code, it will prompt you to download some recommended extensions... Do that...

### Recommended Extensions

#### [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

Code linter for TypeScript and JavaScript

#### [Mocha Sidebar](https://marketplace.visualstudio.com/items?itemName=maty.vscode-mocha-sidebar)

Sidebar test runner for Mocha Tests

## TODO: List

- Finish this documentation...
7 changes: 7 additions & 0 deletions mocharc.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": [
"ts-node/register",
"module-alias/register"
],
"spec": "./test/**/*.test.ts"
}
Loading

0 comments on commit 01134c0

Please sign in to comment.