-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
42 lines (35 loc) · 1.07 KB
/
main.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const express = require("express");
const cors = require("cors");
//const axios = require("axios");
require("dotenv").config();
const { google } = require("googleapis");
const app = express();
const port = 4000;
app.use(cors());
const youtube = google.youtube({
version: "v3",
auth: process.env.APIKEY,
});
// https://www.googleapis.com/youtube/v3/search?key=${apikey}&type=video&part=snippet&q=alkioty
app.use(express.json());
app.get("/", (req, res) => {
res.send("Hello world from server 😎");
});
app.get("/search-with-googleapis", async (req, res, next) => {
try {
const searchQuery = req.query.searchQuery;
const response = await youtube.search.list({
part: "snippet",
q: searchQuery,
type: "video",
});
//const title = response.data.items.map((item) => item.snippet.title);
res.send(response.data.items);
} catch (error) {
//next(error)
console.log("There is an error: ", error);
}
});
app.listen(port, () => {
console.log("App is started and running on port: ", port);
});