From 951adbef3d9d19e9bed450f3a9bdec6ce6219ec7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 8 Aug 2017 19:09:28 +0200 Subject: [PATCH] n-api: add napi_get_node_version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `napi_get_node_version`, to help with feature-detecting Node.js as an environment. Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/14696 Reviewed-By: Kyle Farnung Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen --- doc/api/n-api.md | 31 ++++++++++++++++++++ src/node.cc | 3 +- src/node_api.cc | 14 +++++++++ src/node_api.h | 4 +++ src/node_api_types.h | 7 +++++ src/node_version.h | 4 +++ test/addons-napi/test_general/test.js | 5 ++++ test/addons-napi/test_general/test_general.c | 20 +++++++++++++ 8 files changed, 87 insertions(+), 1 deletion(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 5b7c97d15af6a5..0009a279309daf 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -3285,6 +3285,35 @@ callback invocation, even if it has been successfully cancelled. ## Version Management +### napi_get_node_version + + +```C +typedef struct { + uint32_t major; + uint32_t minor; + uint32_t patch; + const char* release; +} napi_node_version; + +NAPI_EXTERN +napi_status napi_get_node_version(napi_env env, + const napi_node_version** version); +``` + +- `[in] env`: The environment that the API is invoked under. +- `[out] version`: A pointer to version information for Node itself. + +Returns `napi_ok` if the API succeeded. + +This function fills the `version` struct with the major, minor and patch version +of Node that is currently running, and the `release` field with the +value of [`process.release.name`][`process.release`]. + +The returned buffer is statically allocated and does not need to be freed. + ### napi_get_version