A skeleton project that will get you up and running with Node, Express, & ES6 in Docker.
Caveat: This is very opinionated, there are other ways to do this. But, I think this is a best practice.
FROM node:4.4.0
MAINTAINER Josh Finnie <josh.finnie@trackmaven.com>
RUN npm install -g pm2@1.0.2 babel-core@6.7.2
ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /code && cp -a /tmp/node_modules /code
ADD .babelrc /code/.babelrc
ADD app /code/app
WORKDIR /code/
CMD ["pm2", "start", "/code/app/app.json", "--no-daemon"]
web:
build: .
ports:
- "1234:1234"
volumes:
- ./app:/code/app
env_file:
- .env
'use strict';
import http from 'http';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import express from 'express';
import api from './api';
console.log("in server/index.js");
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use('/api', api());
app.server = http.createServer(app);
app.server.listen(process.env.PORT || 1234);
console.log(`Started on port ${app.server.address().port}.`);
export default app;
{
"apps": [
{
"name": "server",
"script": "/code/app/index.js",
"watch": ["./"],
"ignore_watch" : ["node_modules"],
"watch_options": {
"usePolling": true
}
}
]
}
require('babel-core/register');
require('./server');
'use strict';
import { Router } from 'express';
export default function() {
let api = Router();
api.get('/', (req, res) => {
res.json({
version: '1.0'
});
});
return api;
}