TypeScript Node JS project 01: CLI calculator with inquirer prompt and chalk alert in Node JS

Опубликовано: 07 Октябрь 2024
на канале: TypeScript Insights
1,392
19

Getting Started with Your Node.js Project

This guide will help you set up and configure a Node.js project with TypeScript, using best practices for development and publishing. Follow the steps below to get started:

Prerequisites

Make sure you have the following installed on your system:

Node.js LTS version

Project Initialization

1. Open your terminal and navigate to your project directory.

2. Run the following command to initialize your project with default values:

```bash
npm init -y
```

3. You can now customize your `package.json` file as needed.

TypeScript Setup

1. Install TypeScript:

```bash
npm install typescript
```

2. Initialize TypeScript configuration:

```bash
npx tsc --init
```

3. Start TypeScript compiler in watch mode:

```bash
npx tsc -w
```

Dependencies

Install the required dependencies for your project:

```bash
npm install inquirer @types/inquirer chalk @types/chalk ts-node @inquirer/prompts
```

Configuration Changes

`tsconfig.json`

Update your `tsconfig.json` file with the following changes:

```json
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
// ...other options
},
// ...other sections
// Uncomment and modify if you want to save .js files in a different directory
// "outDir": "./dist",
}
```

`package.json`

Modify your `package.json` by adding the following line:

```json
{
// ...other settings
"type": "module"
}
```

Publishing Your Package

1. Sign up for an account on the [npm website](https://www.npmjs.com/signup).

2. In your command prompt, bump the version of your package:

```bash
npm version patch
```

3. Publish your package to npm:

```bash
npm publish
```

Congratulations! Your Node.js project with TypeScript is now configured, and you're ready to develop and publish your package.

For more information and advanced configurations, refer to the official documentation of the tools and libraries used.
```

Feel free to copy and paste this markdown code into your `readme.md` file on GitHub. Make sure to adjust any paths, details, or additional explanations according to your project's requirements.Sure, here's the updated text in `readme.md` format for GitHub:

```markdown
Getting Started with Your Node.js Project

This guide will help you set up and configure a Node.js project with TypeScript, using best practices for development and publishing. Follow the steps below to get started:

Prerequisites

Make sure you have the following installed on your system:

Node.js LTS version

Project Initialization

1. Open your terminal and navigate to your project directory.

2. Run the following command to initialize your project with default values:

```bash
npm init -y
```

3. You can now customize your `package.json` file as needed.

TypeScript Setup

1. Install TypeScript:

```bash
npm install typescript
```

2. Initialize TypeScript configuration:

```bash
npx tsc --init
```

3. Start TypeScript compiler in watch mode:

```bash
npx tsc -w
```

Dependencies

Install the required dependencies for your project:

```bash
npm install inquirer @types/inquirer chalk @types/chalk ts-node @inquirer/prompts
```

Configuration Changes

`tsconfig.json`

Update your `tsconfig.json` file with the following changes:

```json
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
// ...other options
},
// ...other sections
// Uncomment and modify if you want to save .js files in a different directory
// "outDir": "./dist",
}
```

`package.json`

Modify your `package.json` by adding the following line:

```json
{
// ...other settings
"type": "module"
}
```

Publishing Your Package

1. Sign up for an account on the [npm website](https://www.npmjs.com/signup).

2. In your command prompt, bump the version of your package:

```bash
npm version patch
```

3. Publish your package to npm:

```bash
npm publish
```

Congratulations! Your Node.js project with TypeScript is now configured, and you're ready to develop and publish your package.

For more information and advanced configurations, refer to the official documentation of the tools and libraries used.
```

Feel free to copy and paste this markdown code into your `readme.md` file on GitHub. Make sure to adjust any paths, details, or additional explanations according to your project's requirements.