0

I am using trying to use grammarapi using nodejs. My code seems to be fine but doesn't know why it is showing status_code =301 not 200 I have no idea how to fix it. pls, suggest some solution.

error :

trailers: {},
  rawTrailers: [],
  aborted: false,
  upgrade: false,
  url: '',
  method: null,
  statusCode: 301,
  statusMessage: 'Moved Permanently',
  client: TLSSocket {
    _tlsOptions: {
      allowHalfOpen: undefined,
      pipe: false,
      secureContext: [SecureContext],

My code:

const express = require('express');
const https = require('https');

const app = express();


app.get("/", function(req, res){
     const url = "https://www.stands4.com/services/v2/grammar.php?uid=1001&tokenid=tk324324&text=i%20loves%20you&format=json"
     
     https.get(url, function(response){
         console.log(response);
     })
});


app.listen(port = 3000, function(){

    console.log("Server is running on port 3000 ");
});
Nitin Saini
  • 507
  • 2
  • 10
  • 26
  • 1
    You'll need to follow the redirect, here's [one question](https://stackoverflow.com/questions/7323932/how-do-you-follow-an-http-redirect-in-node-js) discussing it. – Phix Apr 29 '21 at 18:32
  • @Phix Thanks I worked i replaced `const https = require('https');` with `var https = require('follow-redirects').https;` It worked now the statuscode is 200. – Nitin Saini Apr 29 '21 at 18:46

0 Answers0