

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 자세히 알아보기: 이 안내서에서 사용한 앱 살펴보기
<a name="gettingstarted-linux-explore-app-source"></a>

**중요**  
이 AWS OpsWorks Stacks 서비스는 2024년 5월 26일에 서비스 수명이 종료되었으며 신규 및 기존 고객 모두에서 비활성화되었습니다. 가능한 한 빨리 워크로드를 다른 솔루션으로 마이그레이션하는 것이 좋습니다. 마이그레이션에 대한 질문이 있는 경우 [AWS re:Post](https://repost.aws/) 또는 [AWS Premium Support](https://aws.amazon.com/support)를 통해 AWS Support 팀에 문의하세요.

이 주제에서는이 연습을 위해 OpsWorks Stacks가 인스턴스에 배포하는 앱을 설명합니다.

앱의 소스 코드를 보려면 [opsworks-windows-demo-nodejs](https://github.com/awslabs/opsworks-windows-demo-nodejs) GitHub 리포지토리의 콘텐츠를 로컬 워크스테이션의 빈 디렉터리에 압축 해제하세요. 쿡북을 배포한 인스턴스에 로그인해 `/srv/mylinuxdemoapp` 디렉터리의 내용을 살펴볼 수도 있습니다.

`index.js` 파일은 앱에 가장 중요한 코드를 포함하고 있습니다.

```
var express = require('express');
var app = express();
var path = require('path');
var os = require('os');
var bodyParser = require('body-parser');
var fs = require('fs');

var add_comment = function(comment) {
  var comments = get_comments();
  comments.push({"date": new Date(), "text": comment});
  fs.writeFileSync('./comments.json', JSON.stringify(comments));
};

var get_comments = function() {
  var comments;
  if (fs.existsSync('./comments.json')) {
    comments = fs.readFileSync('./comments.json');
    comments = JSON.parse(comments);
  } else {
    comments = [];
  }
  return comments;
};

app.use(function log (req, res, next) {
  console.log([req.method, req.url].join(' '));
  next();
});
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }))

app.set('view engine', 'jade');
app.get('/', function(req, res) {
  var comments = get_comments();
  res.render("index",
    { agent: req.headers['user-agent'],
      hostname: os.hostname(),
      nodeversion: process.version,
      time: new Date(),
      admin: (process.env.APP_ADMIN_EMAIL || "admin@unconfigured-value.com" ),
      comments: get_comments()
    });
});

app.post('/', function(req, res) {
  var comment = req.body.comment;
  if (comment) {
    add_comment(comment);
    console.log("Got comment: " + comment);
  }
  res.redirect("/#form-section");
});

var server = app.listen(process.env.PORT || 3000, function() {
  console.log('Listening on %s', process.env.PORT);
});
```

이 파일이 하는 일은 다음과 같습니다.
+ `require`는 이 웹 앱이 예상대로 실행되는 데 필요한 일부 종속 코드가 포함된 모듈을 로드합니다.
+ `add_comment` 및 `get_comments` 함수는 `comments.json` 파일에 정보를 작성하고 이 파일에서 정보를 읽어 옵니다.
+ `app.get`, `app.listen`, `app.post`, `app.set`, `app.use`에 대해서는 [Express API Reference](http://expressjs.com/4x/api.html)를 참조하세요.

 배포를 위해 앱을 만들고 패키징하는 방법은 [애플리케이션 소스](workingapps-creating.md#workingapps-creating-source) 단원을 참조하세요.