-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (23 loc) · 901 Bytes
/
index.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
// HINTS:
// 1. Import express and axios
import express from "express";
import axios from "axios";
// 2. Create an express app and set the port number.
const app= express();
// 3. Use the public folder for static files.
app.use(express.static("public"));
const API_url="https://secrets-api.appbrewery.com/random"
// 4. When the user goes to the home page it should render the index.ejs file.
// 5. Use axios to get a random secret and pass it to index.ejs to display the
app.get("/",async (req,res)=>{
try {
const result=await axios.get(API_url);
res.render("index.ejs",{secret:result.data.secret,user:result.data.username,});
} catch (error) {
console.log(error.response.data);
res.status(500);
}
});
// secret and the username of the secret.
// 6. Listen on your predefined port and start the server.
app.listen(3000,()=>{console.log("running")});