在IIS上部署Node JS应用

时间:2018-06-28 14:14:10

标签: node.js iis deployment node-modules

我去将Node js应用程序上传到iis 我已经为iis和url write安装了节点js

我使用express和hbs渲染主页 当我打开localhost并运行应用程序时,我可以看到节点js(server.js 代码而不是页面(index.hbs)

请给我建议...

也许与web.config文件有关?

server.js代码

const express = require('express');
const hbs = require('hbs');
const fs = require('fs');
const port = process.env.PORT || 3000;

var app = express();
//this line is for makeing parts of the website dynamic and use it inside any page
hbs.registerPartials(__dirname + '/views/partials')
app.set('view engine', 'hbs');


app.use((req, res, next) => {
  var Now = new Date().toString();
  var log = Now + req.method + req.url + req.ip;
  console.log(log);
fs.appendFile('server.txt', log + '\n', (err)=> {
  if (err) {
    var errorm = 'error';
    console.log('error writing to file');
    fs.appendFile('server.txt', errorm);
  }
});
  next();
});
// stop all pages until we add next();
//app.use((req, res, next) => {
//  res.render('maintance.hbs');
//});
  app.use(express.static(__dirname + '/public'));
//create a function and then call the function form any page ( footer.hbs)
hbs.registerHelper('getCurrentYear', () => {
return new Date().getFullYear()
});



app.get('/about', (req, res) => {
  res.render('about.hbs', {
    pagetitle: "tamir",
    title: "32432432432",
  });
});
app.get('/', (req, res) => {
  res.render('home.hbs', {
    pagetitle: "tamir",
    title: "32432432432",
  });
});

app.get('/github', (req, res) => {
  res.render('github.hbs', {
    pagetitle: "tamir",
    title: "32432432432",
  });
});


app.get('/bad', (req, res) => {
  res.send({
    errormessage: 'this is error',
  });
});


app.listen(port, () => {
  console.log('server is up');
});

home.hbs

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>tamir</title>
    </head>
    <body>
    {{> title}}
      {{> footer}}

    </body>
      </html>

请咨询

0 个答案:

没有答案