However, as of version 6.1.0, you can use a new feature of npm init called the. You also learned about some of benefits to working with TypeScript.įinally, you set up a Node project using the Express framework, but compiled and ran the project using TypeScript.Historically, the npm init command was soley used to create a new package.json file. In this tutorial, you learned about why TypeScript is useful for writing reliable JavaScript code. The lint command is the same as we ran in the previous step, minus the use of the npx prefix which is not needed in this context. This will compile and then run the generated output with node. When looking at the start command, you’ll see that first the tsc command is run, and then the node command. In the snippet above, you updated the main path to be the compiled app output, and added the start and lint commands to the scripts section. Run the following command from inside your project directory to install the TypeScript: Now that your npm project is initialized, you are ready to install and set up TypeScript. Step 2 - Configuring the TypeScript Compiler You can always update this information later in your package.json file. The -y flag tells npm init to automatically say “yes” to the defaults. To get started, create a new folder named node_project and move into that directory: You can accomplish this by following the How to Install Node.js and Create a Local Development Environment guide for your operating system. Prerequisitesīefore you begin this guide, you will need Node.js installed on your system. You will build an Express application using TypeScript and transpile it down to JavaScript code. In this tutorial you will set up a Node project with TypeScript. Here are some benefits of using TypeScript: Note: TypeScript is technically a super-set of JavaScript, which means that all JavaScript code is valid TypeScript code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |