Skip to content

Instantly share code, notes, and snippets.

@davidwwu
Forked from bitgord/Quick-ES6-Setup-Heroku
Last active April 27, 2017 05:34
Show Gist options
  • Save davidwwu/bd616b7aa6cc7d7dab868ad29741ecab to your computer and use it in GitHub Desktop.
Save davidwwu/bd616b7aa6cc7d7dab868ad29741ecab to your computer and use it in GitHub Desktop.
Quick setup to use ES6 with Heroku
// First download node, create new folder
// Cd into new folder, npm and git init
// Create heroku app
heroku create
// install babel cli (to do compiling), babel presets (to compile the right features), express (web server)
npm install babel-cli babel-preset-es2015 express
// Create file .babelrc and add json
{
"presets": ["es2015"]
}
// Create app folder with files app.js and greeter.js and require dependencies
// Add code to app.js
import express from 'express';
import greeter from './greeter.js';
var app = express();
app.get('/', function (req, res) {
res.send(greeter());
});
app.listen(process.env.PORT || 3000);
// Add code to greeter.js
function greeter (msg = 'this works') {
return msg;
};
// Export greeter
module.exports = greeter;
//add thiese lines in package.json
"scripts": {
// Tell Heroku how to start application in package.json
"start": "node ./dist/app/app.js",
// Tell Heroku how to build application in package.json
"build": "babel app/*.js -d dist"
}
// From terminal run command
// It compiles code beforehand so it doesnt save in memory (and slow down app)
// Moves all files in app folder into a dist file
// In dist babel compiles the code to be compatible with heroku
// Do not update these files
npm run build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment