-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummyserver.js
70 lines (58 loc) · 2.12 KB
/
dummyserver.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require("dotenv").config();
const express = require('express')
const cors = require('cors');
const bodyParser = require('body-parser');
const fileUpload = require('express-fileupload');
const { spawn } = require('child_process');
const path = require('path'); // Add this line
const { error } = require("console");
const app = express()
app.use(cors({
origin: '*'
}));
//Connect Database
// connectDB()
//Init middleware
app.use(express.json({extended: false}))
app.use(fileUpload());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.post("/scores", async (req, res) => {
if (!req.files || !req.files.resume) {
return res.status(400).json({ error: "No resume file provided" });
}
const { jobDescription } = req.body;
const { resume } = req.files;
const resumeFilePath = path.join(__dirname, 'uploads', resume.name); // Construct the file path
console.log("Resume file path:", resumeFilePath);
// Move the file to the desired location
resume.mv(resumeFilePath, (err) => {
if (err) {
console.error("Error moving file:", err);
return res.status(500).send({ success: false, message: "Error moving file: " + err.message });
}
});
const pythonProcess = spawn("python3", ["resume-score.py", resumeFilePath, jobDescription]);
let score = "";
pythonProcess.stdout.on("data", (data) => {
score += data.toString();
});
pythonProcess.stderr.on("data", (data) => {
console.error("Error executing Python script:", data.toString());
});
pythonProcess.on("close", async (code) => {
if (code === 0) {
console.log("Score:", score);
res.send(score);
console.log("Received file:", req.files.resume.name);
console.log("Job description:", req.body.jobDescription);
} else {
console.error("Error getting score");
res.status(500).send({ success: false, message: "Error getting score" });
}
});
});
const PORT = process.env.PORT || 5001
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});