$ node --check some.js $ node --check some-invalid.js /Users/stefanjudis/test.js:3 }); ^ SyntaxError: Unexpected token } at checkScriptSyntax (bootstrap_node.js:457:5) at startup (bootstrap_node.js:153:11) at bootstrap_node.js:575:3
On that note: I came accross the vm module which was mentioned in the replies to the tweet. The
const vm = require('vm'); const script = new vm.Script('var a =');
The constructor of
vm.Script throws an exceptions if there are any syntax errors.
This module looks quite interesting. So, if you're dealing with generated code you might want to check it out. ;)