-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (25 loc) · 985 Bytes
/
index.js
File metadata and controls
30 lines (25 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require("express");
const bodyParser = require("body-parser");
const {spawn} = require("child_process");
const path = require("path")
const app = express();
app.set('view engine', 'ejs');
app.set("views", path.join(__dirname, "views"))//configuring templates files to ejs extension
app.use(express.static(path.join(__dirname, "public")));//location of static file
app.get("/",async(req,res)=>{
let username = req.query.username;
if(username){
const pyProg = await spawn('python',['Checker.py',username]);
pyProg.stdout.on('data',(data)=>{
res.render("index.ejs",{data:data.toString().trim(),status:200,result:"show"});
});
pyProg.stderr.on('data',(data)=>{
res.render("index.ejs",{data:data.toString(),status:404,result:"show"});
});
}else{
res.render("index.ejs",{result:"hide"});
}
});
app.listen(process.env.PORT || 3000,()=>{
console.log("listining at port 3000");
})