Skip to content

Commit

Permalink
boiler plate
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdwoKIM committed Jul 5, 2022
1 parent 22be9ac commit 1206bfc
Show file tree
Hide file tree
Showing 14 changed files with 1,851 additions and 0 deletions.
172 changes: 172 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@

# Created by https://www.toptal.com/developers/gitignore/api/node,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=node,visualstudiocode

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# Support for Project snippet scope
.vscode/*.code-snippets

# Ignore code-workspaces
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/node,visualstudiocode

.DS_Store
11 changes: 11 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"watch": [
"src",
".env"
],
"ext": "js,ts,json",
"ignore": [
"src/**/*.spec.ts"
],
"exec": "ts-node --transpile-only ./src/index.ts"
}
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "node-typescript-init",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon",
"build": "tsc && node dist"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.13",
"@types/mongoose": "^5.11.97",
"@types/node": "^17.0.25",
"nodemon": "^2.0.15",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
},
"dependencies": {
"dotenv": "^16.0.0",
"express": "^4.17.3",
"express-validator": "^6.14.0",
"mongoose": "^6.3.1"
}
}
23 changes: 23 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import dotenv from "dotenv";

// Set the NODE_ENV to 'development' by default
process.env.NODE_ENV = process.env.NODE_ENV || "development";

const envFound = dotenv.config();
if (envFound.error) {
// This error should crash whole process

throw new Error("⚠️ Couldn't find .env file ⚠️");
}

export default {
/**
* Your favorite port
*/
port: parseInt(process.env.PORT as string, 10) as number,

/**
* MongoDB URI
*/
mongoURI: process.env.MONGODB_URI as string,
};
4 changes: 4 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// controller index file
export {

}
41 changes: 41 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import express, { Request, Response, NextFunction } from "express";
const app = express();
import connectDB from "./loaders/db";
import routes from './routes';
require('dotenv').config();

connectDB();

app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.use(routes); //라우터
// error handler

interface ErrorType {
message: string;
status: number;
}

app.use(function (err: ErrorType, req: Request, res: Response, next: NextFunction) {

res.locals.message = err.message;
res.locals.error = req.app.get("env") === "production" ? err : {};

// render the error page
res.status(err.status || 500);
res.render("error");
});

app
.listen(process.env.PORT, () => {
console.log(`
################################################
🛡️ Server listening on port 🛡️
################################################
`);
})
.on("error", (err) => {
console.error(err);
process.exit(1);
});
17 changes: 17 additions & 0 deletions src/loaders/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mongoose from "mongoose";
import config from "../config";

const connectDB = async () => {
try {
await mongoose.connect(config.mongoURI);

mongoose.set('autoCreate', true);

console.log("Mongoose Connected ...");
} catch (err: any) {
console.error(err.message);
process.exit(1);
}
};

export default connectDB;
8 changes: 8 additions & 0 deletions src/modules/responseMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const message = {
NULL_VALUE: '필요한 값이 없습니다.',
NOT_FOUND: '존재하지 않는 자원',
BAD_REQUEST: '잘못된 요청',
INTERNAL_SERVER_ERROR: '서버 내부 오류'
}

export default message;
15 changes: 15 additions & 0 deletions src/modules/statusCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const statusCode = {
OK: 200,
CREATED: 201,
NO_CONTENT: 204,
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
CONFLICT: 409,
INTERNAL_SERVER_ERROR: 500,
SERVICE_UNAVAILABLE: 503,
DB_ERROR: 600,
};

export default statusCode;
19 changes: 19 additions & 0 deletions src/modules/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const util = {
success: (status: number, message: string, data?: any) => {
return {
status,
success: true,
message,
data,
};
},
fail: (status: number, message: string, data?: any) => {
return {
status,
success: false,
message,
};
},
};

export default util;
9 changes: 9 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//router index file
import { Router } from 'express';


const router = Router();



export default router;
4 changes: 4 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//service index file
export {

}
Loading

0 comments on commit 1206bfc

Please sign in to comment.