Advertisement
dev017

http server (basic) I'll update little by little

Jul 29th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import express from "express";
  2. import cors from "cors";
  3.  
  4. const app = express();
  5. app.use(cors());
  6.  
  7. app.get("/", (req, res) => {
  8.   res.send("this is a test");
  9. });
  10.  
  11. app.use((err, req, res, next) => {
  12.   res.status(500).send("something went wrong");
  13. });
  14.  
  15. app.post("/", (req, res) => {
  16.   const data = req.body;
  17.   console.log(data);
  18.   res.send("OK");
  19. });
  20.  
  21. app.get("/files/:file", (req, res) => {
  22.   const fileName = req.params.file;
  23.   res.sendFile(fileName);
  24. });
  25.  
  26. app.listen(30, () => {
  27.   console.log("server is running on port 30");
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement