Variable scope in javascript module

Dmitry Volyntsev xeioex at
Fri Oct 26 09:02:20 UTC 2018

Hi Alex,

Can you, please, share your code?

You can also try to play with njs code in the command line interface.

For example:

interactive njs 0.2.3

v.<Tab> -> the properties and prototype methods of v.
type for more information

>>function my(){var g = 'init'; console.log(g); (function() {g = 'anon'})(); console.log(g) }; my()

CLI, is also available in docker
docker run -i -t nginx:latest /usr/bin/njs

> On 26 Oct 2018, at 09:16, alweiss <nginx-forum at> wrote:
> Hi team !,
> Regarding the sample here :
> I have an issue trying to use JS module : variable hoisting and global/local
> scope doesn't behave as expected. When i try to reassign the resp variable
> (as you do after declaring it), the value assigned in the done function is
> not brought outside of the done function to the bacthAPI function.
> So if resp is initialised with 0 and reassign as 1 in the done funtion, at
> the end, resp would = 0.
> I had a look to explanation here
> and seems to behave differently in nginx implementation of JS.
> Would it be some OS settings outside of NGINX preventing this to work as it
> should normally work with javascript ? Any dependency on an OS package ?
> Thanks !
> BR
> Alex
> Posted at Nginx Forum:,281699,281699#msg-281699
> _______________________________________________
> nginx mailing list
> nginx at

More information about the nginx mailing list