Node.js - EJS example

后端 未结 3 527
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 15:14

I am trying to use Embedded Javascript renderer for node. I installed it using npm, as given here: https://github.com/visionmedia/ejs

And I have the following code, but

3条回答
  •  猫巷女王i
    2021-02-05 15:38

    try this: (assuming you have the express and ejs modules installed)

    var express = require('express');
    var app = express.createServer();
    app.configure(function() {
        app.use(express.bodyParser());
        app.use(express.static('./static/'));
        app.use(app.router);
    });
    app.set('view engine', 'ejs');
    app.set('view options', {
        layout: false
    });
    app.get('/', function(req, res) {
    res.render('index', {
        message : 'De groeten'
    });
    });
    app.listen(3000);
    

    and put a view in './views'. call it 'index.ejs' and fill it with some html:

    
    
    
    
    
    
    

    <%= message %>

    works for me!

提交回复
热议问题