简体   繁体   中英

Send data from nodejs to ejs?

Can we send data to another client ejs i's, in another server?

I tried to do:

res.render('/visi-web/home/www/elasticsearch/views/index.ejs',  {result:result});

And that's not working.

var elasticsearch = require('elasticsearch');
var express = require('express');
var app = express();
var http = require("http");
var server = http.createServer(app);
app.get('/', function(req, res){
...
res.render('/visi1-sih-web/home/www/elasticsearch/views/index.ejs',  {result:result});
});
}
});

server.listen(3333);

Well,you doing it wrong way.
After looking your code,When you hit '/',it load index.ejs
.There is no need to give detail path.

Use following syntax.

app.render('index', { result: 'result });

When you set your template engine to ejs or something else, there is no need to give extension.

Also ,Please check your view path is defined or not containing index.ejs.
Just give relative path for index.ejs. means if you say

app.use(express.static(__dirname + '/public'));

and within publlic folder there is view folder,then you should written in this way.

app.render('view/index', { result: 'result }).


No need to give public folder name in path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM