본문 바로가기
IT/NodeJS

없는 page 라우팅 처리 예제

by 골든크랩 2022. 7. 18.
728x90
반응형

// 모듈을 추출합니다.
var express = require('express');

// 서버를 생성합니다.
var app = express();

// 라우터를 설정합니다.
app.get('/index', function (request, response) {
  response.send('<h1>Index Page</h1>');
});

// 그외 모든 페이지에 대한 디폴트 처리
app.all('*', function (request, response) {
  response.status(404).send('<h1>ERROR - Page Not Found</h1>');
});

// 서버를 실행합니다.
app.listen(4000, function () {
  console.log('Server running at http://127.0.0.1:4000');
});

728x90
반응형

댓글