By the end of this step, you'll have a simple working program in Node!
npm install -D typescript @types/node
The -D flag installs the packages as development dependencies, which means they won't be included in your production build.
{
"compilerOptions": {
"baseUrl": ".",
"target": "esnext",
"module": "esnext",
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"moduleResolution": "Node",
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["./src/**/*.ts"],
"exclude": ["node_modules"]
}
rootDir is where your TypeScript files are locatedoutDir is where your compiled JavaScript files will go (you won't modify these - they're generated from your TypeScript files)include specifies the files to include in the compilationexclude specifies the files to exclude from the compilationstrict enables all strict type checking optionsesModuleInterop allows you to use ES module syntaxmoduleResolution specifies how modules are resolvedskipLibCheck skips type checking all declaration filesbaseUrl allows you to use paths relative to the project root{
...
"type": "module",
"scripts": {
"build": "npx tsc",
"start": "node dist/main.js",
"dev": "npx tsc && node dist/main.js"
},
...
}
The npx command allows us to run the tsc command without installing TypeScript globally.
function main() {
console.log("Hello, world!");
}
main();
npm run dev
If you see "Hello, world!" printed in the console, you're good to go!
Run and submit the CLI tests.