0

I am parsing wikipedia documents and using the npm html-to-text converter package to extract just the text from various wikipedia pages. I am encountering issues when trying to log / send this content to be used on the client side.

Here is my implementation with the npm package:

 var stringer = htmltext.fromString(data, {
              wordwrap: 130
 });

 console.log(stringer) // returns [object Object]
 console.log(typeof stringer); // returns string
 console.log(util.inspect(stringer)); // returns '[object Object]'

As you can see in the comments, the first console log appears to represent the variable as an object but the second shows that is a string. How can this be?

4
  • Try using console.dir instead of log Commented Aug 1, 2016 at 6:35
  • Try stringer.toString(); . Commented Aug 1, 2016 at 6:37
  • console.dir gave me '[object Object]' and stringer.toString() gave me [object Object]. Not really sure what to make of that. Commented Aug 1, 2016 at 6:46
  • Maybe it is a string and the string content is legitimately [object Object]? I would look further up the stack, finger pointing at at the library, if your not doing anything else in-between getting the string and logging that is. Commented Aug 1, 2016 at 6:53

1 Answer 1

2

What are you passing into htmltext.fromString()?

Are you sure you aren't passing an object into there which is converting to string as [object Object]?

For example, if I type the following into a node console I get what you're seeing. :)

 > var htmltotext = require("html-to-text")
 undefined
 > htmltotext.fromString({})
 '[object Object]'
 >

The usage illustrates that .fromString() expects a string input.

Sign up to request clarification or add additional context in comments.

1 Comment

Turns out I was passing in an object. I though it was a string but I was wrong. Now I feel dumb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.