Node.js Exercises in - Typescript or Javascript?

Hi campers,

I’m going through the Node sections (Quality Assurance, API/Microservices), and I’m using the boilerplates. Maybe this is a dumb question, but are they written in Typescript or Javascript? I can’t seem to tell the difference. I would sometimes encounter “spell errors” in the code, which indicates that the code has type safety, but I’m under the impression that is it NOT Typescript.

  • Is Node.js written in Typescript for Best Practice?
  • Or, is the boilerplate just written in Typescript?
  • In what instances does one use Typescript over Javascript?

If someone can enlighten me, I would really appreciate it! :pray:

Hello there,

I am not too sure what you are referring to…so some more information (examples probably easiest) would help.

What I can answer:

  • Nodejs has no clue how to read TypeScript. Nodejs is its own environment, and uses a specific subset of JavaScript. TypeScript is a superset of JavaScript - everything in JavaScript is in TypeScript, but not everything in TypeScript is JavaScript.
  • Every single freeCodeCamp backend boilerplate is written as a Nodejs app - no TypeScript. (excluding any of the Python stuff)

Remember, just because JavaScript is dynamically typed does not mean it does not care about types; all types are still relevant.

Some extra stuff to research:

  • JavaScript (in a Node.js env) is an interpreted language
  • TypeScript is a compiled language, which just so happens to typically be compiled into JavaScript, before being executed.

Hope this helps

Hi @Sky020, thanks that is helpful!

Let me give you a concrete example:

When I type this into a Node.js environment in, you see that the program indicates an “error” at the end of expression, the red squiggle under the last “)”. When I hover over it, the error message that shows up is “[typescript]: Expression expected”. I 'm just trying to understand what is going on there, and why it says “typescript”.

1 Like

They could be using the TypeScript language server behind the scenes. VS Code does this even in in regular JavaScript files.

It looks like that error is originating from another line though. I don’t see anything wrong with the code there.

Sometimes syntax errors can be really confusing, and that’s generally true for almost any programming language. If there’s an error a few lines above that it might be confusing the language server which is why you’re seeing a weird message there.

If you’re able to share the whole file I might be able to figure out exactly what’s happening.

1 Like

Thanks @dannyjamesfletcher. I think that sometimes mark syntax as errors as you are writing and making changes. After a while the “error mark” disappeared.

1 Like