We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

TypeScript Setup

npm stands for "Node Package Manager". By installing Node.js, you've gained some new commands:

  • node - The JavaScript runtime. This will let you run your application files.
  • npm - The package manager. This manages dependencies, metadata, and allows you to specify "scripts" to run.
  • npx - The package runner. Run a command from a local or remote npm package.

Most TS devs don't run the node commands directly, they use it within an npm script.

Assignment

npm init

This command will prompt you with a series of questions. For this project, you can either press Enter for the recommended defaults or follow the prompts.

npm install -D typescript @types/node tsx
console.log("Hello, World!");
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "moduleResolution": "Node"
  },
  "include": ["./src/**/*.ts"],
  "exclude": ["node_modules"]
}
...
  "type": "module",
  "scripts": {
    "start": "tsx ./src/index.ts"
  },
...

This enables your project to use ES modules and adds a "start" script to this project that runs index.ts using the tsx typescript executable.

npm start

And you should see your "hello world" message logged to the console!

.gitignore

A .gitignore file is used to tell Git which files or folders to ignore when committing changes to a repository. This is useful for ignoring files that are specific to your local development environment or files that should not be tracked in the repository, such as compiled files or sensitive information.

Submit the CLI tests from your project's root. There's no penalty on failure for this lesson.