Node.js app on AWS for beginner

2019-06-08 17:18发布

I started learning node.js a couple weeks ago and just finished my first small project, a basic live chat website using socket.io and express. The structure for my project looks like this:

ChatApp
   |
   |____backend.js                      // node server side code
   |
   |____ static
   |        |
   |        |_____ libs
   |                 |
   |                 |___ app.js        // front end logic
   |                 |
   |                 |___ jquery.min.js                       
   |____ views
            |
            |_____ index.html           // Client website

My goal right now is to learn how to use AWS to make my application available so people on different machines can talk to one another, not just me on my local server. I tried following this guide which uses Elastic Beanstalk to deploy a sample repository, but I'm having a hard time seeing how to translate it to my folder structure, since they don't even have an HTML for instance.

My server code looks like this:

//*****************//
// Sets up backend //
//*****************//
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var express = require('express');
server.listen(8080);
app.use(express.static(__dirname + '/views'));
app.use(express.static(__dirname + '/static'));
var users = [];

//*****************//
// Sends out html  //
//*****************//
app.get('/', function(req, res){ // Main page
    res.render('index.html');
});

//*************************//
// Handles socket requests //
//*************************//
io.on("connection", handleIO); // Called when user connects

function handleIO(socket){
    console.log('Client connected...');
    // Bunch of socket.io code I didn't think was necessary to add
}

Anyways, I was wondering if any of you enlightened folks could help a noob out with deploying his first website. If you could either give me a general outline or point me to one I'd really appreciate it as AWS can be pretty intimidating when first starting out. Thanks.

3条回答
ゆ 、 Hurt°
2楼-- · 2019-06-08 17:39

start with the AWS docs and get a free account on AWS, make your hand dirty.Make things break things and again fix them, this is how you will learn AWS.

Regarding study material 1. AWS DOCS 2. REinvent videos on youtube 3. Buy a Pluralsite account they have very good course over these.

Start with Ec2 and VPC

查看更多
我想做一个坏孩纸
3楼-- · 2019-06-08 17:42

Boxfuse lets you deploy your Node.js app to AWS effortlessly in literally two steps from within your project directory:

  1. npm-bundle: creates a tgz including your app and all the required node modules (install using: npm install -g npm-bundle)
  2. boxfuse run -env=prod:
    • Creates a minimal image containing the contents of the tgz bundle as well as the Node.js runtime, the Linux kernel and a bootloader
    • Pushes that image in the secure Boxfuse Vault
    • Converts it into an AMI
    • Creates a new domain name
    • Provisions an elastic IP or an ELB (depending on the app type you configured)
    • Creates a security group with the correct ports mapped
    • Launches a new EC2 instance and ensures it is healthy
    • Assign the elastic IP to the instance

Boxfuse is based on 3 principles: Immutable Infrastructure, Minimal Images and Blue/Green deployments with zero downtime.

Boxfuse also comes with out-of-the-box support for auto-scaling, relational databases and fast local development and testing on VirtualBox.

We have a tutorial you can follow to get started in 5 minutes: https://boxfuse.com/getstarted/nodejs

Disclaimer: I am the founder and CEO of Boxfuse

查看更多
萌系小妹纸
4楼-- · 2019-06-08 17:44

I would say jumping straight into Amazon Web Services would be a mistake as AWS is just an abstraction layer on millions of tasks that you can perform as a Cloud Administrator.

If you do not have the basic concepts of server administration or have not worked in a similar capacity, it can prove to be counter-productive.

Still if you are willing to make the jump, here are the steps I would recommend:

  1. Learn to create an EC2 instance
  2. Setup/install required software on your EC2 instance
  3. Transfer your code to the EC2 instance
  4. Configure/run your application.

If it helps, EC2 is just a VPC with shell access and you can use it through the command line as you normally would a desktop linux.

查看更多
登录 后发表回答