Notice
Recent Posts
Recent Comments
Link
As i wish
[Node JS] Express를 활용한 간단한 웹서버 만들기 본문
간단하게 express를 이용해서 node js 서버를 만들어보겠습니다.
먼저 npm, node 가 설치 되어있다고 가정합니다.
설치 방법은 생각보다 매우 간단합니다.
1. 원하는 폴더 이름을 만듭니다.
$ mkdir auto-aoj
2. npm init 을 해줍니다.
$ npm init
-> 그럼 pacakge.json 이 만들어지는데 여기에 설치한 노드 모듈들이 정리 되는것을 보실 수 있습니다.
3. 그 외 웹서버에 필요한 모듈들을 설치해줍니다.
$ npm i express body-parser
4. index.js 를 만들어줍니다.
$ vi index.js
index.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.raw());
console.log('Process node version', process.version);
app.use('/', function (req, res) {
res.send('Express server running.');
});
app.listen(8080, () => {
console.log('Express server is running on http://localhost:8080');
});
5. index.js 를 실행시켜줍니다.
$ node index.js
'Node JS' 카테고리의 다른 글
AWS Lambda 로 가벼운 API 만들기 (0) | 2020.03.04 |
---|---|
[Node] Node.js, NPM 최신버전으로 업그레이드하기 (0) | 2020.02.12 |
[Node JS] Node 서버에서 이미지 s3로 업로드 (0) | 2020.01.18 |
Comments