Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning String with Express post

I have this app.js file:

let express = require('express')
let app = express()
let Clarifai = require('clarifai')

app.use(express.urlencoded({extended: true}))
app.use(express.static('./public'))
let link = app.post('/route', (req, res) => {
    let linkString = req.body.link
    res.send(JSON.stringify(linkString))
})

app.listen(3000)

const capp = new Clarifai.App({
    apiKey: 'MyAPIKeyIsHere'
   });

predict = capp.models.initModel({id: Clarifai.FOOD_MODEL, version: "aa7f35c01e0642fda5cf400f543e7c40"})
      .then(generalModel => {
        return generalModel.predict(link)
      })
      .then(response => {
        var concepts = response['outputs'][0]['data']['concepts']
        console.log(concepts)
})

console.log('Express app running on port 3000')
console.log(link)

I am trying to return a string from the app.post method but it returns a JSON file. How should I do it exactly?

like image 320
Nikolay Avatar asked May 09 '26 20:05

Nikolay


1 Answers

You can explicitly set the content type to text/html, before sending the data.

res.set('Content-Type', 'text/html');
res.send(JSON.stringify(linkString));
like image 119
Hassaan Hasan Avatar answered May 12 '26 09:05

Hassaan Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!