Skip to content

Instantly share code, notes, and snippets.

View sonha's full-sized avatar

Simon sonha

  • Ha Noi
View GitHub Profile
@sonha
sonha / sds
Created July 8, 2016 09:36
sd
<?php echo 'baba';?>
@sonha
sonha / event.js
Last active July 12, 2016 06:42
event.js
var info = {
"name" : "sonha",
"age" : 12
}
var events = require("events");
var eventEmitter = new events.EventEmitter();
var connectHandler = function connected(err,data) {
if(err) {
console.log(err);
@sonha
sonha / mysql.js
Created July 12, 2016 08:45
mysql
var http = require('http');
mysql = require('mysql');
var connection = mysql.createConnection({
user : "root",
password : "",
database : "nodejs"
});
@sonha
sonha / demo.js
Created July 14, 2016 01:46
Demo route in NodeJS
var http = require("http");
var server = http.createServer(function(req, res) {
console.log("Incoming Request" + req.method, "-" , req.url);
if(req.method == "GET" && req.url =="/") {
res.writeHead(200, {"Content-Type" : "application/json"});
res.write("This is home page");
res.end();
}
.info {
background: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lap trinh NodeJS Tai Ha Noi</title>
<link rel="stylesheet" type="text/css" href="/public/css/index.css">
</head>
<body>
<div class="info">Trung tam lap trinh Codeto</div>
<h1>Khoa hoc NodeJS Can Ban</h1>
var http = require("http");
var fs = require("fs");
var path = require("path");
//request
//response : tra ve ket qua cho nguoi dung, dinh nghia kieu du lieu se tra ve
var server = http.createServer(function(req, res) {
console.log("Incoming Request" , req.method, '- ', req.url);
//Route, check truong hop url giong nhau
var users = [
{
"id" : 1,
"name" : "Simon Ha",
},
{
"id" : 2,
"name" : "Kevil Ba",
}
];
var http = require("http");
var fs = require("fs");
var path = require("path");
var model = require("./model");
//request
//response : tra ve ket qua cho nguoi dung, dinh nghia kieu du lieu se tra ve
var server = http.createServer(function(req, res) {
console.log("Incoming Request" , req.method, '- ', req.url);
var express = require("express");
var app = express();
app.get('/', function(req, res){
res.send("This is first application");
});
app.listen(3000);