EXPRESS-API-TEMPLATE
├── node_modules
├── src
│ ├── bin
│ │ └── www.js
| ├── database
| | ├── query.js
| | └── mysql.config.js
│ ├── routes
│ │ ├── api
│ │ │ ├── index.js
│ │ │ ├── some-project
│ │ │ | ├── some-project.controller.js
│ │ │ | └── index.js
│ │ │ └── some-project2
│ │ │ ├── some-project2.controller.js
│ │ │ └── index.js
│ │ └── helper
│ │ ├── aws
│ │ │ └── index.js
│ │ └── index.js
│ └── app.js
├── .babelrc
├── .editorconfig
├── .eslintrc.json
├── .gitignore
├── .prettierrc
├── nodemon.json
├── package.json
├── README.md
└── yarn.lock || package-lock.json
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
"start": "node ./src/bin/www"
import logger from 'morgan';
import express from 'express';
import cookieParser from 'cookie-parser';
import indexRouter from './routes/index';
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use('/v1', indexRouter);
export default app;
npm install @babel/cli @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/register @babel/runtime @babel/node --dev @babel/plugin-transform-async-to-generator @babel/plugin-transform-arrow-functions babel-plugin-module-resolver --dev
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-transform-async-to-generator"],
["@babel/plugin-transform-arrow-functions"],
["@babel/transform-runtime"],
[
"module-resolver",
{
"root": "./src",
"alias": {
"@": "./src"
}
}
]
]
}
# install nodemon
yarn add nodemon --dev
npm i nodemon
{
"watch": [
"package.json",
"nodemon.json",
".eslintrc.json",
".babelrc",
".prettierrc",
"src/",
".env"
],
"verbose": true,
"ignore": ["*.test.js", "*.spec.js","node_modules"]
}
...
"scripts": {
"prestart": "babel ./src --out-dir build",
"start": "nodemon ./build/bin/www",
"dev": "nodemon --exec babel-node ./src/bin/www",
},
...
# install elsint and prettier
yarn add eslint eslint-config-airbnb-base eslint-plugin-import prettier --dev
npm install eslint eslint-config-airbnb-base eslint-plugin-import prettier --dev
{
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
},
"extends": ["airbnb-base"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"indent": ["warn", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-console": 1,
"comma-dangle": [0],
"arrow-parens": [0],
"object-curly-spacing": ["warn", "always"],
"array-bracket-spacing": ["warn", "always"],
"import/prefer-default-export": [0]
}
}
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
...
"scripts": {
"prestart": "babel ./src --out-dir build",
"start": "nodemon ./build/bin/www",
"dev": "nodemon --exec babel-node ./src/bin/www",
"lint": "./node_modules/.bin/eslint ./src",
"pretty": "prettier --write '**/*.{js,json}' '!node_modules/**'",
"postpretty": "npm run lint --fix"
},
...
npm install dotenv
yarn add dotenv
import dotenv from 'dotenv';
dotenv.config();
export const testEnvironmentVariable = process.env.TEST_ENV_VARIABLE;
EXPRESS-API-TEMPLATE
├── node_modules
├── src
│ ├── bin
│ │ └── www.js
| ├── database
| | ├── query.js
| | └── mysql.config.js
│ ├── routes
│ │ ├── api
│ │ │ ├── index.js
│ │ │ ├── some-project
│ │ │ | ├── some-project.controller.js
│ │ │ | └── index.js
│ │ │ └── some-project2
│ │ │ ├── some-project2.controller.js
│ │ │ └── index.js
│ │ └── helper
│ │ ├── aws
│ │ │ └── index.js
│ │ └── index.js
│ └── app.js
├── .babelrc
├── .editorconfig
├── .eslintrc.json
├── .gitignore
├── .prettierrc
├── nodemon.json
├── package.json
├── README.md
└── yarn.lock || package-lock.json
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
"start": "node ./src/bin/www"
import logger from 'morgan';
import express from 'express';
import cookieParser from 'cookie-parser';
import indexRouter from './routes/index';
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use('/v1', indexRouter);
export default app;
npm install @babel/cli @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/register @babel/runtime @babel/node --dev @babel/plugin-transform-async-to-generator @babel/plugin-transform-arrow-functions babel-plugin-module-resolver --dev
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-transform-async-to-generator"],
["@babel/plugin-transform-arrow-functions"],
["@babel/transform-runtime"],
[
"module-resolver",
{
"root": "./src",
"alias": {
"@": "./src"
}
}
]
]
}
# install nodemon
yarn add nodemon --dev
npm i nodemon
{
"watch": [
"package.json",
"nodemon.json",
".eslintrc.json",
".babelrc",
".prettierrc",
"src/",
".env"
],
"verbose": true,
"ignore": ["*.test.js", "*.spec.js","node_modules"]
}
...
"scripts": {
"prestart": "babel ./src --out-dir build",
"start": "nodemon ./build/bin/www",
"dev": "nodemon --exec babel-node ./src/bin/www",
},
...
# install elsint and prettier
yarn add eslint eslint-config-airbnb-base eslint-plugin-import prettier --dev
npm install eslint eslint-config-airbnb-base eslint-plugin-import prettier --dev
{
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
},
"extends": ["airbnb-base"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"indent": ["warn", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-console": 1,
"comma-dangle": [0],
"arrow-parens": [0],
"object-curly-spacing": ["warn", "always"],
"array-bracket-spacing": ["warn", "always"],
"import/prefer-default-export": [0]
}
}
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
...
"scripts": {
"prestart": "babel ./src --out-dir build",
"start": "nodemon ./build/bin/www",
"dev": "nodemon --exec babel-node ./src/bin/www",
"lint": "./node_modules/.bin/eslint ./src",
"pretty": "prettier --write '**/*.{js,json}' '!node_modules/**'",
"postpretty": "npm run lint --fix"
},
...
npm install dotenv
yarn add dotenv
import dotenv from 'dotenv';
dotenv.config();
export const testEnvironmentVariable = process.env.TEST_ENV_VARIABLE;
EXPRESS-API-TEMPLATE
├── node_modules
├── src
│ ├── bin
│ │ └── www.js
| ├── database
| | ├── query.js
| | └── mysql.config.js
│ ├── routes
│ │ ├── api
│ │ │ ├── index.js
│ │ │ ├── some-project
│ │ │ | ├── some-project.controller.js
│ │ │ | └── index.js
│ │ │ └── some-project2
│ │ │ ├── some-project2.controller.js
│ │ │ └── index.js
│ │ └── helper
│ │ ├── aws
│ │ │ └── index.js
│ │ └── index.js
│ └── app.js
├── .babelrc
├── .editorconfig
├── .eslintrc.json
├── .gitignore
├── .prettierrc
├── nodemon.json
├── package.json
├── README.md
└── yarn.lock || package-lock.json
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
"start": "node ./src/bin/www"
import logger from 'morgan';
import express from 'express';
import cookieParser from 'cookie-parser';
import indexRouter from './routes/index';
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use('/v1', indexRouter);
export default app;
npm install @babel/cli @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/register @babel/runtime @babel/node --dev @babel/plugin-transform-async-to-generator @babel/plugin-transform-arrow-functions babel-plugin-module-resolver --dev
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-transform-async-to-generator"],
["@babel/plugin-transform-arrow-functions"],
["@babel/transform-runtime"],
[
"module-resolver",
{
"root": "./src",
"alias": {
"@": "./src"
}
}
]
]
}
# install nodemon
yarn add nodemon --dev
npm i nodemon
{
"watch": [
"package.json",
"nodemon.json",
".eslintrc.json",
".babelrc",
".prettierrc",
"src/",
".env"
],
"verbose": true,
"ignore": ["*.test.js", "*.spec.js","node_modules"]
}
...
"scripts": {
"prestart": "babel ./src --out-dir build",
"start": "nodemon ./build/bin/www",
"dev": "nodemon --exec babel-node ./src/bin/www",
},
...