Git Product home page Git Product logo

techtalk20170322's Introduction

Intro

this is a demo source code for tech talk 2017/03/22. demostrating the cutting-edge way to do an nodejs server including:

  • test-driven
  • all es6 features -- mostly async function pattern
  • the next version of koa
  • middlewares and routers stack
  • ORM and mocked data/service
  • flow

check each commit for more detail

  1. setup the first router
  2. first orm model
  3. better error handling
  4. authenticate middleware
  5. create account. mock objects
  6. add relationship between models

Setup Envionment

my local tools versions (or npm installed globally)

  • git v2.10.1
  • node v7.4.0
  • cnpm v4.4.2
  • babel-node v6.18.0
  • mocha v3.2.0
  • mysql v5.7.17
  • direnv v2.10.0

my local envirionment (.envrc)

export PORT=3000
export AUTH_SECRET=ilabs-intro
export MYSQL_DB=ilabs
export MYSQL_USERNAME=rexsheng
export MYSQL_PASSWORD=
export MYSQL_HOST=localhost
export MAIL_ACCOUNT=(your account)
export MAIL_PASSWORD=(your password)

get started

git init
npm init

install babel (presets and plugins)

cnpm i -D babel-core babel-loader babel-polyfill babel-preset-es2015 babel-preset-stage-0
cnpm i -D babel-plugin-transform-flow-strip-types babel-plugin-transform-runtime

your .babelrc should look like:

{
  "presets": ["es2015", "stage-0"],
  "plugins": [
    "transform-runtime",
    "transform-flow-strip-types"
  ]
}

plan to use koa2 for http service, sequelize for ORM, jwt for authenticate, and we do test-driven develop.

cnpm install koa@latest koa-body@next koa-router@next --save
cnpm install boom jsonwebtoken --save
cnpm install sequelize --save
cnpm install chai sqlite3 sequelize-fixtures superagent --save-dev

setup mysql & sqlite3

mysql> create database ilabs;
mysql> grant all on ilabs.* to ''@'localhost';

setup fixtures.yml for test

(start playing)

techtalk20170322's People

Contributors

b051 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.