Diogo Guimaraes Posted August 8, 2017 at 04:13 PM Report #606495 Posted August 8, 2017 at 04:13 PM Boas, Estou a começar a experimentar NodeJS e então encontro-me com uma dúvida. Tenho um servidor web em node a correr uma pasta estatica no entanto queria devolver o conteudo de uma função no index.html. Segue o código que tenho: SERVIDOR var express = require('express'); var app = express(); var externalFunctions = require('./include/functions.js'); app.use(express.static('public')) app.listen(3000, function () { console.log('Example app listening on port 3000!') }) Ficheiro de Funções exports.myDateTime = function () { return Date(); }; Index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <p><!-- Quero apresentar aqui o retorno da função que tenho disponivel no ficheiro functions.js--></p> </body> </html>
JakeBass Posted September 16, 2017 at 10:07 PM Report #607059 Posted September 16, 2017 at 10:07 PM talvez precises de uma library de templating https://expressjs.com/en/guide/using-template-engines.html
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now