app.js
const app = express()
const port = process.env.PORT || 5000
var cors = require('cors')
var bodyparser= require('body-parser')
app.use(bodyparser.json());
const route=require('./routes')
app.use(cors());
app.use('/api',route)
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
routes.js
const express=require('express');
const Instagram = require('instagram-downloader');
const router=express.Router();
router.get('/',(req,res)=>{
res.json("App Running...")
})
router.get("/inst", async (req,res)=>{
ps=req.query.ps
try {
await Instagram(ps)
.then(data => {
const { entry_data: { PostPage } } = data;
return PostPage.map(post => post.graphql.shortcode_media)
})
.then(images => images.map(img => res.json(img.video_url)))
.then(console.log)
} catch (error) {
res.json(error)
}
})
module.exports=router;
package.json
{
"name": "final",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node apps.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"instagram-downloader": "0.0.0"
}
}
when i run API call http://localhost:5000/api/inst?ps=https://www.instagram.com/p/BaaDHe5AdPH/?utm_source=ig_web_copy_link it returns me a JSON.
when i run same API call (https://reels2.herokuapp.com/api/inst?ps=https://www.instagram.com/p/BaaDHe5AdPH/?utm_source=ig_web_copy_link) on heroku it returns me nothing.
Please help me how can i fix this problem