New Project
Tips for initializing new blank projects
Typescript Environment
Basic environment for executing Typescript scripts.
Commands & Configs
Initialize Node Project
npm init --init-author-name "your-email" -y
Installing TS on Node
Node by default don't recognize Typescript only Javascript.
npm install --save-dev @types/node
npm install --save-dev typescript
Generate the tsconfig.json
file:
npx tsc --init \
--outDir build \
--module commonjs \
--allowJs true \
--removeComments true
or for a more strict configuration:
npx tsc --init \
--outDir build \
--esModuleInterop \
--resolveJsonModule \
--module commonjs \
--allowJs true \
--noImplicitAny true \
--removeComments true
You can add these to configure the folders to include and exclude in transpilation:
{
"compilerOptions": {
},
"include": ["./src"],
"exclude": ["./tests"]
}
Configure Custom Running Commands
To be executed with npm
.
# For Windows only (To execute the removal files/folders)
npm install --save-dev rimraf
{
"scripts": {
// If Windows
"build": "rimraf ./build && tsc",
// If Linux
"build": "rm -rf ./build && tsc",
"test-build": "node build/main.js",
}
}
Optional: Install nodemon
(For Cold Reloading)
nodemon
(For Cold Reloading)To auto reload the project when files change.
npm install --save-dev ts-node nodemon
{
"scripts": {
"dev": "nodemon --watch src -e ts --exec ts-node src/main.ts"
}
}
{
"watch": ["src"],
"ext": ".ts,.js",
"ignore": [],
"exec": "npx ts-node ./src/main.ts"
}
Optional: Install dotenv
(For Env variables)
dotenv
(For Env variables)npm install --save-dev dotenv
{
"exec": "npx ts-node ./src/main.ts"
}
Optional: Install tsconfig-path
(???)
tsconfig-path
(???)npm install --save-dev tsconfig-paths
.gitignore
.DS_Store
node_modules
build
coverage
.env
!.env.example
Running
To run + openning the browser:
npm run dev -- --open
Just running the server:
npm run dev
Express Environment
Basic environment for executing an Express
(RestAPI) project.
Commands & Configs
Initialize the Project
Follow Commands & Configs from Typescript Env
.
Install Main Dependencies
npm install --save express
npm install --save express-validator
npm install --save helmet
npm install --save body-parser
npm install --save-dev @types/express
Optional: Mkdirp
To run mkdir -p
for create folders if don't exist.
npm install --save mkdirp
Optional: JWT Tokens (For JWT Token generation)
npm install --save jsonwebtoken
npm install --save-dev @types/jsonwebtoken
Optional: Async (Async/Parallel execution)
npm install --save async
Optional: Mysql (Mysql connector)
npm install --save mysql2
Optional: Axios
npm install --save axios
Optional: Express-Validator
For Body, Query and Param data validation/sanitization.
npm install --save express-validator
Last updated