WEB/Node.js
-
node.js를 이용하여 채팅하기WEB/Node.js 2016. 11. 15. 16:14
npm install socket.io chatServer.jsconst http = require('http');const fs = require('fs');const socket =require('socket.io'); const server = http.createServer( (request, response) => { fs.readFile('view/chatClient.html','utf-8',(error, data)=>{ response.writeHead(200,{'Content-type':'text/html'}); response.end(data); });}).listen(8000,()=>{ console.log('연결');}); var clients = []; //Socket Server ..
-
RedirectWEB/Node.js 2016. 11. 15. 16:09
http 302 status를 이용한다. if(userId == params.userId && userPassword == params.userPassword) { response.writeHead(302, {'Location':'http://www.naver.com'}); response.end('로그인 성공!'); } else { response.writeHead(302, {'Location':'/login'}); response.end('로그인 실패!'); }
-
form 파라미터 추출WEB/Node.js 2016. 11. 15. 15:49
form에 method를 주지 않으면 기본을 get방식이다.post를 써야 post방식이다. Query Param과 Path Param의 차이는? formServer.js 파일const http = require('http');const fs = require('fs');const url = require('url');const querystring = require('querystring');const ejs = require('ejs');const responseHeader = { 'Content-type':'utf-8'} const userId = 'admin';const userPassword = '1234'; http.createServer( (request, response) => { cons..
-
node.js 경로지정WEB/Node.js 2016. 11. 15. 15:20
ejs파일은 스크립틀릿으로 전달받은 데이터를 브라우저에 뿌려준다이 프로젝트에서는 ejs파일은 하나로 충분하다. Test.js파일const http = require ('http');const fs = require('fs');const ejs = require('ejs'); //추가된 모듈const url = require('url');const person = require('./modules/person.js'); http.createServer( (request, response) => { //localhost:8080/path를 읽어온다.const path = url.parse(request.url).pathname;const personInfo = person.get(path);console.l..
-
node.js 변수 전달WEB/Node.js 2016. 11. 15. 11:00
//모듈 생성const http = require ('http');const fs = require('fs');const ejs = require('ejs'); http.createServer( (request, response) => { //이 파일은 전부 읽으면 에러를 출력해라. fs.readFile('view/Client.ejs','UTF-8', (error, data) => { try { response.writeHead(200, {"Content-Type": "text/html"}); response.end(ejs.render(data,{ 'name':'황수빈', 'message':['성정한','홍석훈','황수빈','이근재','남재현','김명회','윤유진','이재형','이치훈'] }) ); } ..
-
Atom.io 설치WEB/Node.js 2016. 11. 15. 10:32
javascript의 변수 선언 방법var 변수명 = "값"; ecma6의 변수 선언 방법let 변수명 = "값"; ecma6의 상수 선언 방법const 변수명 = "값"; 상수는 객체를 선언할 때 사용한다.변수는 값을 임시 저장할 때 사용한다.const http = require ('http'); ecma6는 function 대신, arrow function을 사용한다. function (request, response){... } == (request, response) => {} cmd에서 npm install ejs를 입력하면 ejs를 사용할 수 있다. template engineejs와 jade중 무엇이 편할까?
-
Nodejs 설치WEB/Node.js 2016. 11. 15. 10:31
var http = require('http'); http.createServer(function (request, response) {response.writeHead(200, {'Content-Type' : 'text/html'});response.end('My name is Lee guen jae!');}).listen(3000, function() {console.log('Server running at http://127.0.0.1:3000/');}); 3000 포트로 서버를 생성합니다.