小编Had*_*ock的帖子

在 @angular-eslint/template 中使用缩进规则

我有一个用 Angular 制作的项目。

我想为 Angular*.html文件设置缩进规则。

我在我的.eslintrc

{
  "files": ["*.html"],
  "extends": [
    "plugin:@angular-eslint/template/recommended"
  ],
  "rules": {
    "indent": [2, 2]
  }
}
Run Code Online (Sandbox Code Playgroud)

但这给了我以下错误:

TypeError: Cannot read property 'start' of undefined
Run Code Online (Sandbox Code Playgroud)

我不明白为什么。


我的全.eslintrc

TypeError: Cannot read property 'start' of undefined
Run Code Online (Sandbox Code Playgroud)

eslint angular angular-eslint

7
推荐指数
1
解决办法
2498
查看次数

如何在模块导入/配置中设置 .env 变量

我想.env在我的应用程序中使用一个文件。

我为此创建了两个文件(一个模块和一项服务):

config.module.ts

import {Module} from '@nestjs/common';
import {ConfigService} from './config.service';

@Module({
    providers: [{
        provide: ConfigService,
        useValue: new ConfigService(`${process.env.NODE_ENV || 'development'}.env`),
    }],
    exports: [ConfigService],
})

export class ConfigModule {}
Run Code Online (Sandbox Code Playgroud)

config.service.ts

import * as dotenv from 'dotenv';
import * as fs from 'fs';

export class ConfigService {
    private readonly envConfig: {[key: string]: string};

    constructor(filePath: string) {
        // stock the file
        this.envConfig = dotenv.parse(fs.readFileSync(filePath));
    }

    // get specific key in .env file
    get(key: string): string {
        return this.envConfig[key];
    }

} …
Run Code Online (Sandbox Code Playgroud)

javascript dependency-injection node.js typescript nestjs

2
推荐指数
1
解决办法
1900
查看次数

在纱线上找不到 pm2 命令

我尝试这个解决方案,但我仍然遇到同样的问题。

yarn global add pm2-> 好的

sudo pm2 status->sudo: pm2: command not found

pm2 status->-bash: pm2: command not found

在我的~/.bashrc我添加以下行:

export PATH=$PATH:usr/bin/pm2
Run Code Online (Sandbox Code Playgroud)

因为whereis pm2返回/usr/bin/pm2但没有任何改变

我也测试了这条路径:yarn bin->/home/user/node_modules/.bin但也没有什么

debian pm2 yarnpkg

1
推荐指数
1
解决办法
4036
查看次数

用于打字稿输入的 DTO、模式或接口的最佳实践是什么

目前,在我的打字稿代码(nestjs)中,我使用控制器中的 DTO 来验证进入 API 的数据,模式用作其余文件中的类型,并且除特殊情况外我不会创建接口。

我试图弄清楚我正在做的事情是否好,或者我是否应该在任何地方使用 DTO 作为类型,或者其他什么?目标是提高代码的质量。

用户集合示例:

user.schema.ts

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

@Schema({ collection: 'users' })
export class User extends Document {
  @Prop()
  name: string;
}

export const UserSchema = SchemaFactory.createForClass(User);
UserSchema.set('timestamps', true);
Run Code Online (Sandbox Code Playgroud)

user.dto.ts

import { IsNotEmpty, IsString, Length } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class UserDto {
  @IsNotEmpty()
  @IsString()
  @Length(3)
  @ApiProperty({ required: true })
  readonly name: string;
}
Run Code Online (Sandbox Code Playgroud)

使用示例:

  • 在带有 dto 的控制器中
async …
Run Code Online (Sandbox Code Playgroud)

typescript nestjs

0
推荐指数
1
解决办法
4097
查看次数