Skip to content

Instantly share code, notes, and snippets.

@bitgord
Created December 12, 2016 02:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bitgord/245535acdfb39f489913c1cf3e6fe6af to your computer and use it in GitHub Desktop.
Save bitgord/245535acdfb39f489913c1cf3e6fe6af 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-presets-es2015 express
// Create file .babelrs and add json
{
"presets": ["es2015"]
}
// Create app folder with files app.js and greeter.js and require dependencies
// Add code to app.js
var express = require('express');
var app = express();
var greeter = require('./greeter.js');
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;
// From terminal run command // It compiles code beforehand so it doesnt save in memory (and slow down app)
babel app/*.js -d dist // Moves all files in app folder into a dist file // In dist babel compiles the code to be compatible with heroku // Do not update this file
// 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"
// Run from terminal
npm run build
@davidwwu
Copy link

good stuff, couple typos: line 8 should read babel-preset-es2015 and line 10 should be .babelrc file

@okobaba1
Copy link

okobaba1 commented Jul 2, 2019

I get an error, babel not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment