Home > Software design >  Is there a way to apply css to json database in node.js?
Is there a way to apply css to json database in node.js?

Time:07-24

I am using express.js and I have a JSON database with some information about books. I am exporting inf. like this:

const books = [
    {
// books
}]
 module.exports = books

I am importing books like this

const employees = require('./book-list')

And the main question: Can I style with CSS or somehow else this database? Full code:

const express = require('express')
const app = express()
const port = 5000
const books = require('./book-list')

app.get('/', (req,res)=>{
    res.status(200).json(books)
})

app.listen(port,()=>{
    console.log(`Server is listening on localhost:${port}`)
})

CodePudding user response:

Browsers do not have any features for the custom styling of JSON.

If you want to control the appearance you need to transform the data into a different format.

CSS can only be applied to HTML and XML.

Presenting the data in an HTML document is the most common approach taken by websites.

This is usually done using a template engine in Express. This is covered by the manual.

  • Related