Jump to content

Recommended Posts

Posted

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>
  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.