syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
What is 2015_0912 Code Challenge?

The 2015_0912 Code Challenge is a learning exercise for students attending this Meetup:

http://www.meetup.com/Dans-Linux-JavaScript-Class/events/225223500/

  • Install Ubuntu 14.04.3 on your laptop
  • Useful: http://releases.ubuntu.com/14.04/ubuntu-14.04.3-desktop-amd64.iso
  • Useful: https://www.virtualbox.org/wiki/Downloads
  • Enhance Ubuntu:
    
    sudo apt-get update
    sudo apt-get upgrade
    
    sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev \
    libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3       \
    libgdbm-dev libsqlite3-dev gitk postgresql postgresql-server-dev-all  \
    libpq-dev emacs wget curl chromium-browser openssh-server aptitude    \
    ruby ruby-dev sqlite3
    
    sudo apt-get update
    sudo apt-get upgrade
    
  • Create account named ann:
    useradd ann -m -s /bin/bash
    passwd ann
    ssh -YA ann@localhost
  • Install Node.js in this folder: ~ann/node/
    Useful: https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-x64.tar.gz
  • Add Node.js to PATH:
    export PATH="/home/ann/node/bin:${PATH}"
  • Run a test:
    which node
    node -e 'console.log("hello world")'
  • Install CoffeScript to test npm:
    which npm
    npm install -g coffee-script
    ls -la /home/ann/node/lib/node_modules/
    which coffee
    coffee -e 'console.log "hello coffee!"'
  • Start work on an app:
    mkdir ~ann/app10
    cd    ~ann/app10
    echo  node_modules > .gitignore
    npm init # Creates package.json (displayed below)
    npm install --save http-server
  • Add HTML file to app: ~ann/app10/index.html
    <html>
      <h1>Hello</h1>
      <script>
        alert('I am alert!');
      </script>
    </html>
    
  • Test the app:
    cd   ~ann/app10/
    node ~ann/app10/node_modules/http-server/bin/http-server
    visit: http://localhost:8080
  • Commit the app to a git repository:
    cd ~ann/app10/
    git init
    git add .
    git commit -am 'hello app10'


At this point I should have the app running on Linux on my laptop.

I can follow more steps to deploy the app to Heroku:
  • Enhance ~ann/app10/package.json so it has an "engines" property:
    {
      "name": "app10",
      "version": "1.0.0",
      "description": "simple app",
      "main": "node_modules/http-server/bin/http-server",
      "scripts": {
        "test": "node /home/ann/app10/hello.js"
      },
      "repository": {
        "type": "git",
        "url": "file:///home/ann/app10"
      },
      "keywords": [
        "code-challenge"
      ],
      "author": "Dan",
      "license": "ISC",
      "dependencies": {
        "http-server": "^0.8.0"
      },
      "engines": {
        "node": "4.0.0"
      }
    }
    
  • Create a one-line Procfile:
    cd ~ann/app10/
    echo 'web: node node_modules/http-server/bin/http-server -p $PORT' > Procfile
  • Install Heroku Toolbelt:
    http://www.google.com/search?q=How+to+install+Heroku+Toolbelt+on+Linux
  • Create Heroku Account (cost: $0.00!):
    https://www.heroku.com
    Memorize login and password
  • Create Blank Heroku App and then git-push my app in:
    cd ~ann/app10/
    heroku auth:login
    heroku create x20150910
    git add .
    git commit -am ready4heroku
    git push heroku master
    I should see something like this:
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ heroku create x20150910
    Creating x20150910... done, stack is cedar-14
    https://x20150910.herokuapp.com/ | https://git.heroku.com/x20150910.git
    Git remote heroku added
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ git add .
    dan@u95:/home/ann/app10 $ git commit -am ready4heroku
    [master b7f0a8f] ready4heroku
     1 file changed, 1 insertion(+), 1 deletion(-)
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ git push heroku master
    Counting objects: 11, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (10/10), done.
    Writing objects: 100% (11/11), 1.04 KiB | 0 bytes/s, done.
    Total 11 (delta 3), reused 0 (delta 0)
    remote: Compressing source files... done.        
    remote: Building source:        
    remote: 
    remote: -----> Node.js app detected        
    remote: 
    remote: -----> Creating runtime environment        
    remote:                
    remote:        NPM_CONFIG_LOGLEVEL=error        
    remote:        NPM_CONFIG_PRODUCTION=true        
    remote:        NODE_ENV=production        
    remote:        NODE_MODULES_CACHE=true        
    remote: 
    remote: -----> Installing binaries        
    remote:        engines.node (package.json):  4.0.0        
    remote:        engines.npm (package.json):   unspecified (use default)        
    remote:                
    remote:        Downloading and installing node 4.0.0...        
    remote:        Using default npm version: 2.14.2        
    remote: 
    remote: -----> Restoring cache        
    remote:        Skipping cache (new runtime signature)        
    remote: 
    remote: -----> Building dependencies        
    remote:        Pruning any extraneous modules        
    remote:        Installing node modules (package.json)        
    remote:        http-server@0.8.0 node_modules/http-server        
    remote:        ├── opener@1.4.1        
    remote:        ├── corser@2.0.0        
    remote:        ├── colors@1.0.3        
    remote:        ├── http-proxy@1.11.2 (eventemitter3@1.1.1, requires-port@0.0.1)        
    remote:        ├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)        
    remote:        ├── portfinder@0.4.0 (async@0.9.0, mkdirp@0.5.1)        
    remote:        ├── union@0.4.4 (qs@2.3.3)        
    remote:        └── ecstatic@0.7.6 (url-join@0.0.1, mime@1.3.4, minimist@1.2.0, he@0.5.0)        
    remote: 
    remote: -----> Caching build        
    remote:        Clearing previous node cache        
    remote:        Saving 1 cacheDirectories (default):        
    remote:        - node_modules        
    remote: 
    remote: -----> Build succeeded!        
    remote:        └── http-server@0.8.0        
    remote:                
    remote: -----> Discovering process types        
    remote:        Procfile declares types -> web        
    remote: 
    remote: -----> Compressing... done, 11.9MB        
    remote: -----> Launching... done, v3        
    remote:        https://x20150910.herokuapp.com/ deployed to Heroku        
    remote: 
    remote: Verifying deploy.... done.        
    To https://git.heroku.com/x20150910.git
     * [new branch]      master -> master
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ 
    dan@u95:/home/ann/app10 $ 
    
  • When I visit the page served by the app, I should see something like this:


That could be considered an adequate code challenge for a two hour Meetup.

If you have questions, e-me:

bikle101@gmail.com


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me