I have an HTML file (index.html
) where I put a form and I want to see a list of elements that are inside a JSON file (elements.json
).
I want to create a server with node.js
, so I create app.js
in this way:
const express = require('express')
const app = express()
const port = 3000
var config = require('./public/js/elements.json');
//static file
app.use(express.static('public'))
app.use('/css', express.static(__dirname+'public/css'))
app.use('/js', express.static(__dirname + 'public/js'))
//set view
app.set('views', './views')
app.set('view engine', 'ejs')
app.get('', (req, res) => {
res.sendFile(__dirname+'/views/index.html')
})
//listen
app.listen(port, () => console.info(`Listening on port ${port}`) )
1. How can I do in my script.js
file (that is in the same directory of elements.json
) to show the elements in a table on my index.html
?
2. When I fill the form in the HTML page, I want to add that element on my JSON file, in order to see it in my list of elements on HTML page. How can I do it?