Spaces:
Sleeping
Sleeping
Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from "express";
|
| 2 |
+
import { exec } from "child_process";
|
| 3 |
+
|
| 4 |
+
const app = express();
|
| 5 |
+
app.use(express.json());
|
| 6 |
+
app.use(express.static("public"));
|
| 7 |
+
|
| 8 |
+
app.post("/run", (req, res) => {
|
| 9 |
+
const code = req.body.code;
|
| 10 |
+
|
| 11 |
+
exec(`node -e "${code.replace(/"/g, '\\"')}"`, (err, stdout, stderr) => {
|
| 12 |
+
if (err) return res.json({ error: stderr });
|
| 13 |
+
res.json({ output: stdout });
|
| 14 |
+
});
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
app.listen(3000, () => console.log("Running"));
|