sandiego

Express, upload file

https://github.com/TechMaster/learn_express

9-3-2017

  • Nodemon (Dùng để auto reload khi thay đổi code)
npm install -g nodemon
https://github.com/remy/nodemon

12-3-2017

Socket io

https://github.com/TechMaster/demo-socketio

14-3-2017

  • Realtime applications

17-3-2017

Các kiểu kết nối client - server (chủ yếu là AJAX - Polling)

https://github.com/TechMaster/cli_serv_com

event_emitter

https://github.com/TechMaster/temperature_socket
Tham khao: http://vietjack.com/nodejs/lop_event_emitter_trong_nodejs.jsp

20-3-2017

Cài Docker

https://docs.docker.com/docker-for-mac

Docker Hub

  • Search 'alpine' - Chạy dòng lệnh để cài alpine
  • Sửa dụng alpine
    • docker run -it alpine /bin/sh
  • Pull image Postgresql

    • docker pull postgres:9.6.2-alpine
  • Kiểm tra container đang chạy

    • docker ps -a
  • Stop 1 container

    • docker stop db
  • Remove 1 container

    • docker rm db

Hướng dẫn

https://github.com/TechMaster/learn-docker/blob/master/postgresql.md

Lệnh trong Docker

  • Hiển thị tất cả images:
docker images
  • Xóa images:
docker rmi <<id>>
  • Không được xóa Container khi vẫn còn Image sinh ra nó (Vì image là bản nén, Container là bản giải nén)

  • Hiển thị tất cả Container

    docker ps -a
    
  • Xóa Container

    docker rm <<id>>
    
  • Chạy container

docker start <<Tên container>>
  • Dừng container
docker stop <<Tên container>>
  • Khởi tạo container từ images (tên images là abcxyz được tạo từ trước)

    docker run -it --name <<tên container>> alpine /bin/sh
    
-t: psendo tty
-i: stdin - input
-d:daemon (để Container chạy ngầm, khi nào dùng lệnh --docker stop <<ten container>>-- thì mới dừng.)
docker run -p 5432:5432 --name db -e POSTGRES_PASSWORD=abc -d -t postgres:9.6.2-alpine

Cai postgresql

https://hub.docker.com
search 'postgres'
Cai ban moi nhat:
cmd : docker pull postgres
Cai theo phien ban
docker pull postgres:9.6.2-alpine

Cai pgAdmin4

5/4/2017

Tạo database, schema bằng câu lệnh

  • Kết nối đến database bằng user: postgres
psql -h localhost -p 5432 -U postgres -W -d postgres
CREATE ROLE dat CREATEDB LOGIN;
ALTER ROLE dat ENCRYPTED PASSWORD 'abc';
CREATE DATABASE dienthoai OWNER dat;
CREATE SCHEMA "cms";

Xem minh dang o schema nao

SHOW search_path;

Muốn vao database

  • Bằng cấp
\connect database;
  • Lớn bé
SET ROLE nam;

Muốn vào schema nao

SET schema 'public';

11/4/2017

Middleware trong Expressjs

Tham khảo: https://expressjs.com/en/resources/middleware.html
  • Body Parser (Dùng để hứng query trên url)

    const bodyParser = require("body-parser")
    // parse application/x-www-form-urlencoded
    // for easier testing with Postman or plain HTML forms
    
    app.use(bodyParser.urlencoded({
        extended: true
    }))
    
  • Serve static resource (Folder 'public' lưu các file css, js trừ file html)

  • app.use('/public', express.static('public'))
    
  • View Template Engine (Lưu file html và dùng nunjuck để truyền dữ liệu vào, được cấu hình để join vào folder 'views')

  • const nunjucks = require('nunjucks')
    nunjucks.configure('views', {
        autoescape: true, //Dùng để nó có thể hiểu được các ký tự đặc biệt
        cache: false,
        express: app,
        watch: true
    })
    app.engine('html', nunjucks.render)
    app.set('view engine', 'html')
    
  • Error Handling Middleware (Hiển thị lỗi, nếu không có thì sẽ hiển thị lỗi và các file bị lỗi như vậy sẽ bị ng dùng nhìn thấy các đường dẫn file)

  • app.use(function (err, req, res, next) {
        console.error(err.stack)
        res.status(500).send('Error: ' + err.message)
    })
    

Bench Mark

ab -n 1000 -c 50 http://localhost:3000 
a: Apache
b: Bench mark
n: total connection
c: concurrent connection

13/4/2017

  • Chia terminal (cmd) thành nhiều tab
linux: sử dụng inux
Mac: sử dụng iterm2

21/09/2017

https truyền dữ liệu dạng public key và private key

results matching ""

    No results matching ""