【问题标题】:Display installed node version on SPA [closed]在 SPA 上显示已安装的节点版本 [关闭]
【发布时间】:2021-05-18 21:18:55
【问题描述】:

我想在我的 Angular 应用程序中显示安装在服务器上的节点版本。 有可能吗?

例如,在我的服务器上,安装了节点12.0.0。我想在我的 Angular SPA 的页面上将此版本号显示为文本。

谢谢,

【问题讨论】:

  • 或许有可能。你尝试了什么?您在网络搜索中发现了什么?另请参阅How to Ask

标签: node.js angular


【解决方案1】:

你可以为此创建一个restful服务。

在 nodejs 中

var exec = require('child_process').exec;
function execute(command, response){
    exec(command, function(error, stdout, stderr){ 
    response.status(200).json({version: stdout});
});
};

app.get('/version', function (request, response) {
    execute('node -v', response);
});

角度

 getVersion(){
    return this.http.get('http://localhost:8000/version')
    .subscribe((resp: any) => {
      console.log('version', resp.version)
    });
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-08
    • 1970-01-01
    相关资源
    最近更新 更多