So, I have a simple node.js server that only serves dynamic content:
var app = require('express')();
app.get('/message/:poster', function(request, response) {
response.writeHeader(200, {'content-type': 'text/html'});
response.end(""+
"<!DOCTYPE html>"+
"<html>"+
"<head>"+
"<title>messages of "+request.params.poster+"</title>"+
"<script src='http://example.com/script.js'></script>"+
"<link rel='stylesheet' href='http://example.com/style.css'>"+
"</head>"+
"<body>"+
""
);
})
app.listen(2345);
Now suppose I want to update my HTML.
And suppose I do not want to restart the server.
Is there any way to achieve this?
I tried to export the part to send to an external file, for example:
module.exports.message = function(request, response) {
response.writeHeader(200, {'content-type': 'text/html'})
response.end(""+
"<!DOCTYPE html>"+
"<html>"+
"<head>"+
"<title>messages of "+request.params.poster+"</title>"+
"<script src='http://example.com/script.js></script>"+
"<link rel='stylesheet' href='http://example.com/style.css'>"+
"</head>"+
"<body>"+
""
);
}
and
var app = require('express')();
app.get('/message/:poster', require('./lib.js').message)
app.listen(2345);
And it works, but if I update lib.js, it does not update. This seems to be a copy of this feature.
Then i tried
var app = require('express')();
app.get('/message/:poster', function(request, response) {
require('./lib.js').message(request, response);
})
app.listen(2345);
.
, ( ). , , (, , ), , n , node, , , , , .
, ? - ? , 100 , -, .
. , jade, ejc ..