Here's the set of steps I follow to test out Ember using Node / Express in Elastic Beanstalk. For reference, here's a test project I've deployed to AWS EB using these steps.
Start a new Ember project, and add in the Express dependencies
create a file named www inside bin folder
Change package.json start script to execute the www script, so Elastic Beanstalk app will runn the Express Server, instead of the Ember server
Create index.js in root folder, that will startup the Express server, and route traffic from '/' to the ember page at /public/ember-app/index.html (note: I used /public/ember-app instead of /public/app because /public/app was breaking the ember build).
Commit / Push to GitHub
Deploy to Elastic Beanstalk
Start a new Ember project, and add in the Express dependencies
npm install -g ember-cli ember new my-awesome-app cd my-awesome-app npm install --save express npm install --save ejs npm install --save path npm install --save debug mkdir bin mkdir views
create a file named www inside bin folder
#!/usr/bin/env node var app = require('../index'); var debug = require('debug')('autocare:server'); var http = require('http'); var port = normalizePort(process.env.PORT || '3000'); app.set('port', port); var server = http.createServer(app); server.listen(port); server.on('error', onError); server.on('listening', onListening); function normalizePort(val) { var port = parseInt(val, 10); if (isNaN(port)) { // named pipe return val; } if (port >= 0) { // port number return port; } return false; } function onError(error) { if (error.syscall !== 'listen') { throw error; } var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; switch (error.code) { case 'EACCES': console.error(bind + ' requires elevated privileges'); process.exit(1); break; case 'EADDRINUSE': console.error(bind + ' is already in use'); process.exit(1); break; default: throw error; } } function onListening() { var addr = server.address(); var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind); }Grant www execute permissions
chmod +x www
Change package.json start script to execute the www script, so Elastic Beanstalk app will runn the Express Server, instead of the Ember server
"scripts": { "build": "ember build", "start": "node ./bin/www", "test": "ember test" }
Create index.js in root folder, that will startup the Express server, and route traffic from '/' to the ember page at /public/ember-app/index.html (note: I used /public/ember-app instead of /public/app because /public/app was breaking the ember build).
var express = require('express'); var path = path = require('path'); var ejs = require('ejs'); var app = express(); app.use(express.static(path.join(__dirname, 'public/ember-app'))); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); app.get("/", function(req, res) { res.sendFile("index.html", { root: "./public/ember-app/" }); }); if (app.get('env') === 'development') { app.use(function(err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: err }); }); } app.use(function(err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: {} }); }); module.exports = app;Create error.ejs template in views folder
<!DOCTYPE html> <html> <head> <title>Error</title> </head> <body> <h1>An Error Has Occurred&bt;/h1> <p> <%= message %> </p> </body> </html>Build Ember App
ember build --environment production --output-path ./public/ember-app
Commit / Push to GitHub
git add // (add files) git commit -m "setting up express" git push
Deploy to Elastic Beanstalk
eb deploy
Great Article
ReplyDeleteThe IEEE Xplore digital library is your gateway to trusted research—journals, conferences, standards, ebooks, and educational courses—with more than 3 million articles to help you fuel imagination, build from previous research, and inspire new ideas.
Final Year Projects for CSE in Node.js
IEEE will pave a new way in knowledge-sharing and spreading ideas across the globe. Project Centers in Chennai for CSE
Node.js Corporate Training
JavaScript Training in Chennai
I've learned something new today, thanks to you. Benefits of an Insulated Attic
ReplyDeleteThank you for sharing such valuable information. It's definitely going to help me in my work. www.insulationsurrey.com
ReplyDelete