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" -yInstalling TS on Node
Node by default don't recognize Typescript only Javascript.
npm install --save-dev @types/node
npm install --save-dev typescriptGenerate the tsconfig.json file:
npx tsc --init \
--outDir build \
--module commonjs \
--allowJs true \
--removeComments trueor for a more strict configuration:
npx tsc --init \
--outDir build \
--esModuleInterop \
--resolveJsonModule \
--module commonjs \
--allowJs true \
--noImplicitAny true \
--removeComments trueYou 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.exampleRunning
To run + openning the browser:
npm run dev -- --openJust running the server:
npm run devExpress 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/expressOptional: Mkdirp
To run mkdir -p for create folders if don't exist.
npm install --save mkdirpOptional: JWT Tokens (For JWT Token generation)
npm install --save jsonwebtoken
npm install --save-dev @types/jsonwebtokenOptional: Async (Async/Parallel execution)
npm install --save asyncOptional: Mysql (Mysql connector)
npm install --save mysql2Optional: Axios
npm install --save axiosOptional: Express-Validator
For Body, Query and Param data validation/sanitization.
npm install --save express-validatorLast updated