본문 바로가기

WEB/Node.js

스마트 출석부 구현 (Node.js)

728x90
반응형

온라인 출석 방법) 특정 숫자를 화면에 띄워주고 해당 숫자를 입력하면 출석이 완료됨.

해당 기능을 Node.js로 구현해보았다! 임의로 지정해준 숫자는 512이다.

var express = require("express");
var app = express();

app.listen(3001, function () {
    console.log("listening on port 3001");
});
app.use(express.urlencoded());


app.get("/", function (req, res) {
    res.sendFile(__dirname + "/public/school.html");
});


app.post('/', function(req, res) {
	console.log(req.body);
	
	function check(input, num){
		if(input==num)
		res.send('출석되었습니다');
	
		else
		res.send('출석번호가 틀렸습니다');
	}
		

	var num=req.body.num;
	var rand=req.body.ran;
	check(num, rand)
});

School.js

 

<html>
<head> </head> 
<body>
<script>
	function getRandomInt(min, max) { 
   	 	return Math.floor(Math.random() * (max - min)) + min;
	}
	
	var a = getRandomInt(100,999);

</script>

<form method="post" action="">

스마트 출석 <br>
<input type="text" name="num" /> 
<input type="submit"> 
<input type="hidden" name="ran" value="512">

</form>
</body>
</html>

School.html

출석 화면
올바르게 숫자 입력 시 뜨는 창

728x90
반응형

'WEB > Node.js' 카테고리의 다른 글

Node.js 파일 업로드 & 다운로드  (0) 2022.12.29
Node.js 방명록 제작  (1) 2022.12.26
Node.js와 MySQL 연동 (express 사용)  (0) 2022.12.26
Node.js로 웹페이지 생성(express 사용)  (0) 2022.12.26
Node.js, NPM  (0) 2022.12.26