-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (32 loc) · 839 Bytes
/
app.js
File metadata and controls
43 lines (32 loc) · 839 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
31
32
33
34
35
36
37
38
39
40
41
42
43
import express from 'express';
import fs from 'fs'
const app = express();
app.get('/',(req,res)=>{
res.send("welcome to my server")
})
app.get("/sign",(req,res)=>{
const {file} =req.query;
const {content}= req.query;
fs.writeFile(file, content, (err) => {
if (err) throw err;
console.log("file created");
});
res.send("file is created ")
});
app.get("/rename",(req,res)=>{
const {oldFile} =req.query;
const {newFile}= req.query;
fs.rename(oldFile, newFile, (err) => {
if (err) throw err;
console.log("file renamed");
});
res.send("file renamed successfully");
});
localhost:3000/
app.get('/:name',(req,res)=>{
const {name} = req.params;
res.send(`welcome to ${name} page`)
});
app.listen(3000,()=>{
console.log("Server is running on port 3000");
})