장준영

BE-feat-server 환경 구축

1 +README.md
2 +package.json
3 +package-lock.json
1 +module.exports = {
2 + env: {
3 + browser: true,
4 + commonjs: true,
5 + es2021: true,
6 + node: true,
7 + },
8 + extends: ['eslint:recommended', 'plugin:prettier/recommended'],
9 + parserOptions: {
10 + ecmaVersion: 12,
11 + sourceType: 'module',
12 + },
13 + rules: {
14 + 'prettier/prettier': [
15 + 'error',
16 + { singleQuote: true },
17 + {
18 + endOfLine: 'auto',
19 + },
20 + ],
21 + 'no-unused-vars': 'warn',
22 + 'no-console': 'off',
23 + 'func-names': 'off',
24 + 'no-process-exit': 'off',
25 + 'object-shorthand': 'off',
26 + 'class-methods-use-this': 'off',
27 + },
28 + };
29 +
...\ No newline at end of file ...\ No newline at end of file
1 +#
2 +node_modules
3 +package-lock.json
4 +.DS_Store
5 +.env
...\ No newline at end of file ...\ No newline at end of file
1 +var createError = require('http-errors');
2 +var express = require('express');
3 +var path = require('path');
4 +var cookieParser = require('cookie-parser');
5 +var logger = require('morgan');
6 +
7 +var indexRouter = require('./routes/index');
8 +
9 +var app = express();
10 +
11 +// view engine setup
12 +app.set('views', path.join(__dirname, 'views'));
13 +app.set('view engine', 'jade');
14 +
15 +app.use(logger('dev'));
16 +app.use(express.json());
17 +app.use(express.urlencoded({ extended: false }));
18 +app.use(cookieParser());
19 +app.use(express.static(path.join(__dirname, 'public')));
20 +
21 +app.use('/', indexRouter);
22 +
23 +// catch 404 and forward to error handler
24 +app.use(function(req, res, next) {
25 + next(createError(404));
26 +});
27 +
28 +// error handler
29 +app.use(function(err, req, res, next) {
30 + // set locals, only providing error in development
31 + res.locals.message = err.message;
32 + res.locals.error = req.app.get('env') === 'development' ? err : {};
33 +
34 + // render the error page
35 + res.status(err.status || 500);
36 + res.render('error');
37 +});
38 +
39 +module.exports = app;
1 +#!/usr/bin/env node
2 +
3 +/**
4 + * Module dependencies.
5 + */
6 +
7 +var app = require('../app');
8 +var debug = require('debug')('server:server');
9 +var http = require('http');
10 +
11 +/**
12 + * Get port from environment and store in Express.
13 + */
14 +
15 +var port = normalizePort(process.env.PORT || '3000');
16 +app.set('port', port);
17 +
18 +/**
19 + * Create HTTP server.
20 + */
21 +
22 +var server = http.createServer(app);
23 +
24 +/**
25 + * Listen on provided port, on all network interfaces.
26 + */
27 +
28 +server.listen(port);
29 +server.on('error', onError);
30 +server.on('listening', onListening);
31 +
32 +/**
33 + * Normalize a port into a number, string, or false.
34 + */
35 +
36 +function normalizePort(val) {
37 + var port = parseInt(val, 10);
38 +
39 + if (isNaN(port)) {
40 + // named pipe
41 + return val;
42 + }
43 +
44 + if (port >= 0) {
45 + // port number
46 + return port;
47 + }
48 +
49 + return false;
50 +}
51 +
52 +/**
53 + * Event listener for HTTP server "error" event.
54 + */
55 +
56 +function onError(error) {
57 + if (error.syscall !== 'listen') {
58 + throw error;
59 + }
60 +
61 + var bind = typeof port === 'string'
62 + ? 'Pipe ' + port
63 + : 'Port ' + port;
64 +
65 + // handle specific listen errors with friendly messages
66 + switch (error.code) {
67 + case 'EACCES':
68 + console.error(bind + ' requires elevated privileges');
69 + process.exit(1);
70 + break;
71 + case 'EADDRINUSE':
72 + console.error(bind + ' is already in use');
73 + process.exit(1);
74 + break;
75 + default:
76 + throw error;
77 + }
78 +}
79 +
80 +/**
81 + * Event listener for HTTP server "listening" event.
82 + */
83 +
84 +function onListening() {
85 + var addr = server.address();
86 + var bind = typeof addr === 'string'
87 + ? 'pipe ' + addr
88 + : 'port ' + addr.port;
89 + debug('Listening on ' + bind);
90 +}
1 +{
2 + "name": "server",
3 + "version": "0.0.0",
4 + "private": true,
5 + "scripts": {
6 + "start": "node ./bin/www",
7 + "dev": "nodemon ./bin/www"
8 + },
9 + "dependencies": {
10 + "cookie-parser": "~1.4.4",
11 + "debug": "~2.6.9",
12 + "express": "~4.16.1",
13 + "http-errors": "~1.6.3",
14 + "jade": "~1.11.0",
15 + "morgan": "~1.9.1"
16 + },
17 + "devDependencies": {
18 + "eslint": "^7.15.0"
19 + }
20 +}
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +/* GET home page. */
5 +router.get('/', function(req, res, next) {
6 + res.json('index3');
7 +});
8 +
9 +module.exports = router;