5

I have some issues in set encoding in node.js. I tried to set encoding to utf8 using writeFile function. But no results. current file I want to set encoding using node.js was encoded in unicode.

1 Answer 1

10

By default, the fs module will write files with an encoding of 'utf8'. UTF-8 is an encoding commonly used in web pages and other documents. File encoding refers to the character set that is used for the contents of the file. Commonly used encodings are 'utf8', 'ascii', 'binary', 'hex', 'base64' and 'utf16le'.

Source from stackabuse.

To write file with encoding

If options is a string, then it specifies the encoding. Example:

fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);

or is options is an object then,

fs.writeFile('message.txt', 'Hello Node.js', {encoding: 'utf8'}, callback);

Check here for more information

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

1 Comment

I tried to create xls file but is not encoding using the above way

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.