본문 바로가기
728x90
반응형

전체 글164

[Node.js_생활코딩]동적인 웹페이지 만들기_함수로 정리하기 여전히 비효율적인 코드가 남아있다. EX ) var http = require('http'); var fs = require('fs'); var url = require('url'); function templateHTML(title, list, body){ return ` WEB ${list} ${body} `; } function templateList(filelist){ var list = ''; var i = 0; while(i < filelist.length){ list = list + `${filelist[i]}`; i = i + 1; } list = list+''; return list; } var app = http.createServer(function(request,response){ .. 2021. 2. 16.
[Node.js_생활코딩]동적인 웹페이지 만들기_글목록 출력하기 이때까지 하드코딩을 하고 있었다. EX ) 이렇게 되면 파일을 하나씩 추가할 때마다 또 새롭게 코드를 작성해야한다. 이를 효율적으로 하기위해서 데이터 폴더 안에있는 파일 개수만큼 반복하는 방법을 사용하자. data에 파일을 하나 추가하고 실행해보니 잘 작동한다! var http = require('http'); var fs = require('fs'); var url = require('url'); var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var pathname = url.parse(_url, true).pathname; i.. 2021. 2. 16.
[Node.js_생활코딩]동적인 웹페이지 만들기_홈(첫화면)페이지 만들기 첫 화면에서는 다른 내용이 보이도록 하자. 조건문 구조는 아래와 같다. var http = require('http'); var fs = require('fs'); var url = require('url'); var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var pathname = url.parse(_url, true).pathname; console.log(pathname); if(pathname === '/'){ if(queryData.id === undefined){ // 없는 값을 호출하려고 할 때 fs.readFile(.. 2021. 2. 16.
[Node.js_생활코딩]동적인 웹페이지 만들기_Not Found Error 현재 주소에 http://localhost:3000/?id=HTML 와 같이 /?id=### 의 형태로 다른 페이지로 넘어가게 구현하고 있다. / 뒤에 설정하지 않은 ###가 들어올 때는 응답하지 않도록 하기 위해 if, else로 사용한다. var http = require('http'); var fs = require('fs'); var url = require('url'); var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var pathname = url.parse(_url, true).pathname; var title = .. 2021. 2. 16.
[Node.js_생활코딩] 동적인 웹페이지 만들기_파일 읽어서 본문 변경 데이터 폴더에 파일 하나씩 생성 모든 파일에 설명 글이 들어가있음. var http = require('http'); var fs = require('fs'); var url = require('url'); var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var title = queryData.id; if(_url == '/'){ title = 'Welcome'; } if(_url == '/favicon.ico'){ return response.writeHead(404); } response.writeHead(200); fs.rea.. 2021. 2. 16.
[Node.js_생활코딩] 동적인 web page 만들기 main.js var http = require('http'); var fs = require('fs'); var url = require('url'); var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var title = queryData.id; if(_url == '/'){ title = 'Welcome'; } if(_url == '/favicon.ico'){ return response.writeHead(404); } response.writeHead(200); var template = ` WEB HTML CSS JavaSc.. 2021. 2. 16.
[MariaDB]CRUD 현재 Create Read Update : update 를 수행해보기 위해서 위의 데이터에 임의로 TEST04를 INSERT 한 뒤, 이를 TEST03으로 바꿔보자. Delete 2021. 2. 16.
[Node.js] MariaDB와 연동하기 1. MariaDB 설치 2. 간이 table 생성 windows 메뉴에서 mariaDB 검색 차례대로 입력 DROP DATABASE IF EXISTS nodejs_test; CREATE DATABASE nodejs_test; DROP USER IF EXISTS nodejs_admin; CREATE USER nodejs_admin@'%' IDENTIFIED BY 'admin'; GRANT ALL PRIVILEGES ON nodejs_test.* to nodejs_admin@'%'; USE nodejs_test; DROP TABLE IF EXISTS users; CREATE TABLE users ( user_key INT NOT NULL AUTO_INCREMENT PRIMARY KEY, user_id VA.. 2021. 2. 16.
[Node.js] 커스텀 모듈 작성 1. 커스텀 모듈 js작성 : cal.js function plus(a,b){ return a+b; } function minus(a,b){ return a-b; } function multiplication(a,b){ return a*b; } function division(a,b){ return a/b; } // 현재 소스를 모듈로 export module.exports = { plus: plus, minus: minus, mult: multiplication, divi: division } 2. 모듈 불러와서 사용하는 js 작성 : useModule.js // require() : 현재 실행하는 폴더 내에 cal.js 모듈 사용 var cal = require('./cal'); console.log.. 2021. 2. 16.
[Node.js] Express framework 설치 및 실행, 800A138F 오류 1. Express framework 설치 (cmd) 작업 폴더로 이동 -> npm install express 2. hello-express.js 작성 (Visual Studio Code) hello-express.js 작성 var express = require('express'); var app = express(); app.get('/', function(req, res) { res.send('Hello World!'); }); app.listen(3000, function() { console.log('Example app listening on port 3000!'); }); 3. cmd 창에서 확인 해당 폴더 -> node hello-express.js [ ERROR ] cmd 창에서 "no.. 2021. 2. 16.
[Node.js]간단한 예제 실행 1. Visual Studio Code를 이용해서 간단한 코드 작성 작업할 폴더 생성 -> hello.js 파일 생성 // Load HTTP module var http = require("http"); // Create HTTP server and listen on port 8000 for requests http.createServer(function(request, response) { // Set the response HTTP header with HTTP status and Content type response.writeHead(200, {'Content-Type': 'text/plain'}); // Send the response body "Hello World" response.end('.. 2021. 2. 16.
[Node.js]Node.js 설치 및 확인 1. Node.js 다운로드 및 설치 ( 특별히 변경할 것 x ) https://nodejs.org/ko/download/ 다운로드 | Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. nodejs.org 2. 설치 확인 cmd 창에서 다음으로 확인 2021. 2. 16.
Type of Triangle Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table: Equilateral: It's a triangle with 3 sides of equal length. 정삼각형 Isosceles: It's a triangle with 2 sides of equal length. 이등변 삼각형 Scalene: It's a triangle with 3 sides of differing lengths. 그냥 삼각형 Not A Triangle: The given valu.. 2020. 6. 19.
Employee Salaries 문제 : Write a query that prints a list of employee names (i.e.: the name attribute) for employees in Employee having a salary greater than 2000 per month who have been employees for less than months. Sort your result by ascending employee_id. SELECT name FROM Employee WHERE months 2000 ORDER BY employee_id asc; Rose Patrick Lisa Amy Pamela Jennifer Julia Kevin Paul Donna Michell.. 2020. 6. 19.
Employee Names 문제 : Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee table in alphabetical order. SELECT name FROM Employee ORDER BY name asc; 2020. 6. 19.
Higher Than 75 Marks 문제 : Query the Name of any student in STUDENTS who scored higher than Marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID. SELECT Name FROM STUDENTS WHERE Marks > 75 ORDER BY RIGHT(NAME, 3), ID ASC; Stuart Kristeen Christene Amina Aamina.. 2020. 6. 19.
HackerRank_18. Weather Observation Station 12 문제 : Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates. SELECT distinct CITY FROM STATION WHERE SUBSTR(CITY, 1, 1) NOT IN ('a', 'e', 'i', 'o', 'u') AND SUBSTR(CITY, -1, 1) NOT IN ('a', 'e', 'i', 'o', 'u'); Baker Baldwin Bass Harbor Beaufort Beaver Island Benedict Bennington Berryton Beverly Bison Blue River B.. 2020. 6. 12.
HackerRank_17. Weather Observation Station 11 문제 : Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates. SELECT distinct CITY FROM STATION WHERE SUBSTR(CITY, 1, 1) NOT IN ('a', 'e', 'i', 'o', 'u') OR SUBSTR(CITY, -1, 1) NOT IN ('a', 'e', 'i', 'o', 'u'); Kissee Mills Loma Mar Sandy Hook Tipton Arlington Turner Slidell Negreet Glencoe Chelsea Chignik La.. 2020. 6. 12.
HackerRank_16. Weather Observation Station 10 문제 : Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates. SELECT distinct CITY FROM STATION WHERE SUBSTR(CITY, -1, 1) NOT IN ('a', 'e', 'i', 'o', 'u'); Kissee Mills Loma Mar Sandy Hook Tipton Arlington Turner Slidell Negreet Chignik Lagoon Hanna City Albany Monument Manchester Prescott Graettinger Sturgis Highwood Bowdon Tyler Watkins Repu.. 2020. 6. 12.
HackerRank_15. Weather Observation Station 9 문제 : Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates. SELECT distinct CITY FROM STATION WHERE SUBSTR(CITY, 1, 1) NOT IN ('a', 'e', 'i', 'o', 'u'); Kissee Mills Loma Mar Sandy Hook Tipton Turner Slidell Negreet Glencoe Chelsea Chignik Lagoon Pelahatchie Hanna City Dorrance Monument Manchester Prescott Graettinger Cahone Sturgis Highwo.. 2020. 6. 11.
728x90
반응형