2

I just upgraded node.js to v6.10.3 and tried to run some test code.

var str = '{"foo": "bar"}';
var obj = JSON.parse(str);
console.log(obj.foo);

I saved this to a file test.js and tried running it from the node command prompt.

Windows Script Host says

'JSON' is undefined

I can open a Chrome window, open the debugger, open the console and enter the same code and it runs correctly.

I have searched google and SO for an explanation, and I find a lot of matches on JSON and undefined, but nothing pertaining to this problem in node.

1
  • It works for me for node v7.8.0. Commented May 9, 2017 at 21:59

1 Answer 1

1

You need to make sure you specify the node executable instead of just the javascript file or double clicking on the javascript file. For example: node test.js. Otherwise Windows will try to use WSH (specifically its JScript engine) to execute the code which contains an older, inferior javascript runtime.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.