김서연

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

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