0

I have and file called server.js which has the code bellow and I wanna have a folder called views and inside that a folder called circles to build the html to load the array showed bellow, but I think I need to change the path of circles I actually never done that, and there's no place to build the html inside the application, thats why I wanna do that so I can build and load the array on the html. I just need the circle part.I'm sorry I have never worked using a node application.

  const express = require('express')
const cors = require('cors')
const app = express()

const circles = [
    {
        id: 1,
        name: 'Twitter',
        image: 'img/twitter.jpg',
        color: '#aa2b31',
        size: 3
    },
    {
        id: 2,
        name: 'Facebook',
        image: 'img/facebook.jpg',
        color: '#63e184',
        size: 1
    },
    {
        id: 3,
        name: 'Skype',
        image: 'img/skype.png',
        color: '#033d49',
        size: 2
    },
]

app.use(express.static('public'))
app.use(cors())

app.get('/', (req, res) => {
    const help = `

    `

    res.send(help)
  })

app.get('/circles', (req, res) => {
    res.send(circles)
})

app.listen(3001, () => {
  console.log('Server listening on port 3001')
})  
Bruno Silva
  • 119
  • 1
  • 8
  • .sendFile() should work –  Apr 16 '19 at 15:10
  • Can you clarify what you are asking? Are you asking how to include code from another js file into this one? Take a look at this answer: https://stackoverflow.com/q/5797852/1806763 – JD D Apr 16 '19 at 15:13
  • no. I wanna just add the path to build a html and load the information inside the variable circles, but if I add a folder called views and inside views I add another folder called circles I will get Cannot get path /views/circles – Bruno Silva Apr 16 '19 at 15:19
  • What do you mean "build html file" What exactly are you trying to build. Do you want to use a templating engine like handlebarsjs and use the `circles` array to fill in the place holders? Or do you simply want to send a JSON response and have the `circles` array in a different file? – Krimson Apr 16 '19 at 16:50
  • Yeah I'm using the template engine EJS – Bruno Silva Apr 16 '19 at 17:01

0 Answers0