title: How to find the location of a javascript syntax error programmatically?
body: <p>I am loading a Node.js module using require. This throws a Syntax Error (an Error object).</p>
  
  <p>Is there a way to get the location in the file where the error occurred?</p>
  
  <p>I can see the stack (below) but I don't have any location information. I know I can use substack's <a href="https://github.com/substack/node-syntax-error" rel="nofollow">node-syntax-error</a>, but is there a way to get similar location info from the Javascript Error object?</p>
  
  <pre><code>SyntaxError: Unexpected identifier
  at Module._compile (module.js:437:25)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  ... // the rest is in my code
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>According to Vadim's comment below, yes that is what I am tempted to do. I see that node throws nice errors. Having a <code>test.js</code> file that contains only <code>abc</code> you get an error from node saying</p>
  
  <pre><code>ReferenceError: abc is not defined
      at Object.&lt;anonymous&gt; (test.js:1:63)
      at Module._compile (module.js:456:26)
      at Object.Module._extensions..js (module.js:474:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
      at Function.Module.runMain (module.js:497:10)
      at startup (node.js:119:16)
      at node.js:901:3
  </code></pre>
  
  <p>Now the question is, is there a node API to do get this error (that the node module.js module uses) such that I don't have to <code>child_process.spawn('node', ['test.js'])</code>?</p>