Unverified Commit d1cca7a3 authored by Jonathan Cunanan's avatar Jonathan Cunanan Committed by GitHub

Merge pull request #6 from jcunanan05/feature/rewriteForArticle

Feature/rewrite for article
parents b37849aa 63e9d05d
{
"presets": ["@babel/preset-env"],
"ignore": ["**/__tests__/**", "*.test.js", "*.spec.js"]
}
# bin folder
bin
# build folder
build
dist
# exclude src
!src/**
\ No newline at end of file
module.exports = {
env: {
es6: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
rules: {
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'import/no-commonjs': 'error'
}
};
......@@ -2,7 +2,7 @@
# Edit at https://www.gitignore.io/?templates=node,macos
## build folder
dist
dist-server
build
### macOS ###
......
# Express with ES6
An skeleton express app that allows you to use ES6 syntax. Generated by express-generator cli.
## How to run
Before anything else, you must have node installed on your machine.
### Running Dev Server
Run on your terminal `npm run watch:dev`, the server will restart everytime you make a change in your code.
### Running Production Server
For stuff like heroku deployment, aws elasticbeanstalk, run `npm run start`
### Other scripts
* `transpile` - convert es6 and beyond code to es5 to a folder named `dist-server`
* `clean` - delete transpiled folder
* `build` - clean and transpile
{
"execMap": {
"js": "babel-node"
},
"watch": ["src/*", "public/*"],
"ext": "js, html, css, json"
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "express-es6-sample",
"version": "0.0.0",
"version": "0.2.0",
"private": true,
"scripts": {
"start": "npm run prod",
"dev": "NODE_ENV=development npm run watch ./src/bin/www",
"prod": "npm run build && NODE_ENV=production node ./dist/bin/www",
"build": "npm run clean && babel ./src --config-file ./.babelrc --out-dir dist",
"clean": "rimraf dist",
"watch": "nodemon --config ./nodemon.json --"
"author": {
"name": "Jonathan Cunanan",
"url": "https://github.com/jcunanan05"
},
"license": "MIT",
"dependencies": {
"bigint-hash": "^0.2.2",
"cookie-parser": "^1.4.4",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.0",
"morgan": "~1.9.0",
"rimraf": "^2.6.3"
"express": "~4.16.1",
"morgan": "~1.9.1",
"nodemon": "^2.0.2",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.1",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/preset-env": "^7.8.4"
},
"nodemonConfig": {
"exec": "npm run dev",
"watch": ["server/*", "public/*"],
"ignore": ["**/__tests__/**", "*.test.js", "*.spec.js"]
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.4.4",
"eslint": "^5.16.0",
"eslint-plugin-import": "^2.17.2",
"nodemon": "^1.19.0"
"babel": {
"presets": ["@babel/preset-env"],
"ignore": ["**/__tests__/**", "*.test.js", "*.spec.js"]
},
"scripts": {
"start": "npm run prod",
"build": "npm-run-all clean transpile",
"server": "node ./dist-server/bin/www",
"dev": "NODE_ENV=development npm-run-all build server",
"prod": "NODE_ENV=production npm-run-all build server",
"transpile": "babel ./server --out-dir dist-server",
"clean": "rimraf dist-server",
"watch:dev": "nodemon"
}
}
......@@ -4,8 +4,9 @@ import cookieParser from 'cookie-parser';
import logger from 'morgan';
import indexRouter from './routes/index';
import usersRouter from './routes/users';
const app = express();
var app = express();
app.use(logger('dev'));
app.use(express.json());
......@@ -14,5 +15,6 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
export default app;
......@@ -4,24 +4,24 @@
* Module dependencies.
*/
import app from '../app';
import debugLib from 'debug';
import http from 'http';
import app from '../app';
import debugLib from 'debug';
import http from 'http';
const debug = debugLib('express-es6-sample:server');
var debug = debugLib('myapp:server');
/**
* Get port from environment and store in Express.
*/
const port = normalizePort(process.env.PORT || '3000');
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
......@@ -60,12 +60,13 @@ function onError(error) {
throw error;
}
var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
/* eslint-disable no-console */
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
......@@ -84,7 +85,8 @@ function onError(error) {
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
console.log(`Listening on ${bind}`);
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
import express from 'express';
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
res.render('index', { title: 'World' });
});
export default router;
import express from 'express'
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
export default router;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Hello</title>
</head>
<body>
<h1>Hello <%= title %></h1>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment