A boilerplate for a node web api application. It's designed to work out-of-the-box.
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® backend api written in TypeScript. It has Mocha 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.
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!
npm run build
npm test
-
There are included vscode specific settings included to streamline things.
-
Using WSL on Windows is just a smoother developer experience.
-
IoC container for typescript.
-
Allows your transpiled code to actually make use of the
paths
section of yourtsconfig.json
file. -
For testing.
-
Assertion library.
Has all the rules/config for ESLint.
Config settings for mocha when running it from the command line.
-
ts-node/register
- for compilation. -
module-alias/register
- for path alias recognition.
-
clean
- removesdist
folder. -
build
- runsclean
and builds app. -
start
- cleans, builds, and starts app. -
test
- runsmocha
with settings inmocharc.jsonc
.
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
{
// ...
"_moduleAliases": {
"@service": "dist/service"
// ...
}
// ...
}
tsconfig.json
{
"compilerOptions": {
// ...
"paths": {
"@service/*": ["./src/service"]
// ...
}
// ...
}
}
include
key is for including any source files that you want VSCode to recognize.
Used only for build to exclude the test
folder in compilation.
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...
Code linter for TypeScript and JavaScript
Sidebar test runner for Mocha Tests
- Finish this documentation...