0

im trying to read a text file with Node express and write it to a HTML tag. i successfully located the file location but i got some weird extra characters. so my txt file has "my second project" only three words ! but i got many other characters at the beginning such as:

{\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf100 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 \f0\fs24 \cf0 my second project }

heres my code (in short):

const fs = require('fs');var title = null;

                        fs.readFile(
                        './public/posts/' + name + '/title.txt',
                        'utf8',
                        (err, data) => {
                            if (err) {
                                console.error(err);
                                return;
                            }
                            console.log('------\n');
                            console.log(data);
                            title = data;
                            res.render('post.ejs', {
                                name,
                                files,
                                pages,
                                title,
                                bio: 'Xxvsdfsdf'
                            });
                        }
                    );

and my ejs file:

<%= titile %>

everything works fine but i wanna get ride from that unwanted extra characters

OT AMD
  • 183
  • 5
  • 19

1 Answers1

1

An RTF file is a text file. It is a storage format for MS Word documents.

If you want to interpret the format and extract some of the document text rather than the formatting, start with a library that reads MS Word documents.

For simple text extraction, a regex might work.

Tom Blodget
  • 20,260
  • 3
  • 39
  • 72