0

I have a node/React set up like

client
    React app here
fonts
node_modules
index.js
package-lock.json
package.json    

In my index.js I'm using the npm package fontkit to get info about a font installed in the fonts folder

const fontkit = require('fontkit');
const font = fontkit.openSync('./fonts/OpenSans-Bold.ttf');
const fontFeatures = font.availableFeatures

console.log(fontFeatures)   

This returns the a list of the Opentype features like:

[ 'lnum',
  'onum',
  'pnum',
  'liga',
  'salt',
  'ss01',
  'ss02',
  'ss03',
  'tnum',
  'kern' ]  

I'd like to be able to use this array in the React app

How can I access the array created in node from the React app

1 Answer 1

1

The easiest way to do this would be to expose an API endpoint that you can call to get this information. So for example, if your React app makes an HTTP request to http://myapp.com/fonts/info, your API could programmatically fetch the font information and return it to the client.

Another option would be to do server-side rendering of your front-end code, in which case you could directly pass the info through a templating engine such as Handlebars or Mustache.

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

Comments

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.