我有一个用 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) 我想.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) 我尝试这个解决方案,但我仍然遇到同样的问题。
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
但也没有什么
目前,在我的打字稿代码(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)
使用示例:
async …
Run Code Online (Sandbox Code Playgroud) nestjs ×2
typescript ×2
angular ×1
debian ×1
eslint ×1
javascript ×1
node.js ×1
pm2 ×1
yarnpkg ×1