-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (25 loc) · 742 Bytes
/
Copy pathapp.js
File metadata and controls
29 lines (25 loc) · 742 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
const express = require("express");
const { exec } = require("child_process");
const app = express();
const port = 3000;
app.get("/test", (req, res) => {
res.send("Test route hit!");
});
app.get("/memex/reddit/:subreddit/:postId", (req, res) => {
const { subreddit, postId } = req.params;
exec(
`python3 reddit_script.py ${subreddit} ${postId}`,
(error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
res.status(500).send("Internal Server Error");
return;
}
console.log(`Python Output: ${stdout}`);
res.send(`Python Output: ${stdout}`);
}
);
});
app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});