김서연

프로젝트 기본생성 및 open api 인증키 추가

node_modules
package-lock.json
var express = require('express');
var bodyParser = require('body-parser');
var request = require('request');
var cheerio = require('cheerio');
var app =express();
app.use(express.urlencoded( {extended : false } ));
app.locals.pretty=true;
app.set('views','./views')
app.set('view engine','pug');
app.use(express.static('public'));
//?page=페이지번호&?perPage=페이지당 데이터수
const $base_url = `https://api.odcloud.kr/api/apnmOrg/v1/list`;
const $key = '4US0H%2BXj%2BmS8IR4YL0%2BUb9H4CcbTr92QxhYULfOEz1DT%2BZaaos4sRfNh6cmAD2Icli862Ysc31%2BaE4pWywDBIA%3D%3D';
//임시
const $page=1;
const $perPage=10;
const $api_url = $base_url + '?returnType=XML&serviceKey='+$key+'&page='+$page+'&perPage='+$perPage;
console.log($api_url);
app.listen(3000,function(){
console.log('Connected 3000 port!');
});
request($api_url,function(err,res,body){
$ = cheerio.load(body);
const $infoList = $('item')
console.log($infoList.html());
console.log($infoList.length);
// let name = $infoList.find('orgnm').text();
// let location = $infoList.find('orgZipaddr').text();
// console.log(`기관명: ${name}, 위치: ${location}`);
})
app.post('/search',function(req,res){
res.send('내가 검색한 지역은 ' + req.body.region);
})
app.get('/',function(req,res){
res.render('main');
})
\ No newline at end of file
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cheerio": "^1.0.0-rc.9",
"express": "^4.17.1",
"pug": "^3.0.2",
"request": "^2.88.2",
"supervisor": "^0.12.0"
}
}
html
head
meta(charset='utf-8')
body
form(action='/search' method="post")
p
input(type='text' name='region' placeholder='지역')
p
input(type='submit')
\ No newline at end of file