0

I use the following command before sending JS files to my server:

node --check <filename>.js

That way I can be sure there are no gross errors before forwarding the file to the server (i.e. a missing ) generates an error).

What I noticed, though, is that node.js does not give me an error if I do not put a semicolon at the end of a line. I would like that to happen, but after looking at the command line options, I just cannot see such a feature.

Is there a way to do that with node.js?

divibisan
  • 11,659
  • 11
  • 40
  • 58
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • 5
    You might want to use [eslint](https://eslint.org/docs/developer-guide/nodejs-api) and then set [`semi: "always"`](https://eslint.org/docs/rules/semi) rule. – kamyl Sep 10 '17 at 09:53

2 Answers2

1

What I noticed, though, is that node.js does not give me an error if I do not put a semicolon at the end of a line.

That's because JavaScript has an error-correction mechanism called automatic semicolon insertion (see this question's answers for more about ASI), where the parser will insert semicolons into the token stream for you if they're missing in many cases. So Node itself isn't going to give you this information.

I would recommend using a proper lint tool instead, such as ESLint, JSHint, or any of several others.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • 1
    I used JSHint before and it was not really working well. I just tried ESLint, now that's way better. I was able to fix a couple of bugs too! – Alexis Wilke Sep 10 '17 at 10:28
0

Its actually not an error if you don't put in a semicolon in javascript. I've seen both kinds of developers some of them prefer it and some of them don't.

I agree with the answer above, you can use linters and they run with IDEs pretty smoothly.

You can correct yourself as you go rather than writing lines of code and at the end, correcting all your syntax errors (which obviously doesn't scale and becomes irritating after a while).

Samarth
  • 431
  • 1
  • 5
  • 13
  • I use `gvim`, yeah, I know... No IDE for me. It's cumbersome and you have to switch once in a while, it's annoying to have to relearn a new one each time. – Alexis Wilke Sep 10 '17 at 10:29