获取目前运行的NodeJS版本

Ori Goren-Bar 阳锐
Ori Goren-Bar 阳锐
  • 更新于
API endpoint: GET /api/node_version
Sample Response:
{"current":{"options":{"loose":false,"includePrerelease":false},"loose":false,"raw":"v12.16.1\n","major":12,"minor":16,"patch":1,"prerelease":[],"build":[],"version":"12.16.1"},"satisfied":true,"recommended":">=10.0"}
 
Shell
curl"http://127.0.0.1:22999/api/node_version"

Node.js

#!/usr/bin/env noderequire('request-promise')({
	url: 'http://127.0.0.1:22999/api/node_version'
}).then(function(data){ console.log(data); },
	function(err){ console.error(err); });

Java

packageexample;

importorg.apache.http.HttpHost;
importorg.apache.http.client.fluent.*;

public classExample {
  public static voidmain(String[] args) throwsException {
    String res = Executor.newInstance()
.execute(Request.Get("http://127.0.0.1:22999/api/node_version"))
.returnContent().asString(); System.out.println(res) }
}

C#

usingSystem;
usingSystem.Net;
usingSystem.Net.Http;
usingSystem.Net.Http.Headers;

public classProgram {
  public static asyncTaskMain() {
    var client = newHttpClient();
    var requestMessage = newHttpRequestMessage {
      Method = HttpMethod.Get,
RequestUri = newUri("http://127.0.0.1:22999/api/node_version") }; var response = await client.SendAsync(requestMessage); var responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseString); } }

Python

#!/usr/bin/env python
print('If you get error "ImportError: No module named requests", please install it:\n$ sudo pip install requests');
import requests

r = requests.get('http://127.0.0.1:22999/api/node_version')
print(r.content)