** i am try to count total word in PDF this is working fine when normal function but this implementation in API node js i didn't got response this is show promise is pending **
const express = require("express")
const app = express()
const fs = require("fs")
const pdf = require("pdf-parse")
let data = fs.readFileSync("pdf/book.pdf")
const port = 3001
app.use(express.json)
function countWords(str) {
str = str.replace(/(^\s*)|(\s*$)/gi, "");
str = str.replace(/[ ]{2,}/gi, " ");
str = str.replace(/\n /, "\n");
return "total number of word this book \n" + str.split(' ')
.length;
}
const s = pdf(data).then(function(data) {
console.log((countWords((data.text))));
});
console.log(s)
app.get("/data", async (req, resp) => {
resp.send(s.then((result) => {
console.log(result)
}))
})
app.listen(port, () => {
console.log(`express listing this port ${port}`);
})
My API not working i didn't got any response this show promise still pending