我是 Angular 的新手,但遇到了问题。
我正在创建一个包含多个兄弟组件的应用程序。当我更新一个组件中的值时,其他组件不会更新。我知道要解决这个问题,我应该使用行为主题。但是我如何用我的服务、组件和所有模板来实现它?
这是我的代码 -
---------------我的服务-------------------------- ——
//import
@Injectable()
export class CoachService {
apiURL = environment.apiURL;
constructor(private http: HttpClient ) { }
coachProfile(token :string)
{
return this.http.post<any>(this.apiURL+'/coach/profile_infos',{
token: token
})
}
updateProfile(info: any, token: string, us_id: string) {
return this.http.post<any[]>(this.apiURL + '/coach/update_profile', {
token: token,
us_id: us_id,
us_lang: info.us_lang,
us_firstname: info.us_firstname,
us_lastname: info.us_lastname,
us_sex: info.us_sex,
us_birthdate: info.us_birthdate,
us_national_number : info.us_national_number,
us_email: info.us_email,
us_gsm: info.us_gsm,
online_profile: info.online_profile,
us_address: info.us_address,
us_zip: info.us_zip,
us_city: info.us_city,
country:{
id: info.country.id …
Run Code Online (Sandbox Code Playgroud) 我试图在节点应用程序启动时预加载 .env 文件。
我有以下配置,但每当我运行时npm run start:dev
都会出现错误。
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"start:dev": "node -r dotenv/config . dotenv_config_path=/.dev.env",
"start:test": "node -r dotenv/config . dotenv_config_path=/.test.env",
"test": "echo \"Error: no test specified\" && exit 1"
},
Run Code Online (Sandbox Code Playgroud)
或者
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"start:dev": "node -r dotenv/config . dotenv_config_path=./.dev.env",
"start:test": "node -r dotenv/config . dotenv_config_path=./.test.env",
"test": "echo \"Error: no test specified\" && …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个用于sharp node package
调整 JPEG/JPG 图像大小的 NodeJS 项目。
问题是Node进程不断地将处理后的文件添加到内存中并且从不释放它。
因此,消耗的内存量随着每个请求而增加,并且永远不会被释放。
调试应用程序后,我意识到Sharp toBuffer API导致了该问题。
我尝试通过创建 acustom writable stream
并用管道来使用替代解决方案sharp Duplex stream
,但最终遇到了同样的问题。
我不明白我是否在这里遗漏了任何东西或者这是一个错误。
分享下面的代码(我删除了不需要的代码以使其紧凑)-
const { Writable } = require("stream");
const { createServer } = require("http");
const { readFileSync } = require("fs");
const sharp = require("sharp");
async function resizeJpeg(input_buffer) {
// initialise file, the response object
const file = { normalisedImage: null, originalImage: null };
// initialise sharp instance using original image buffer
let image = …
Run Code Online (Sandbox Code Playgroud) 在为 Node 项目进行性能测试时,我遇到了一些内存报告,这些报告在性能和内存泄漏方面的解释有点令人困惑。
因此,我使用process.memoryUsage() API生成了报告,该 API 提供了有关以下信息的信息 -
我在每次向服务器发出请求后记录了内存快照,并绘制了 100 个请求的图表 -
图表显示以下信息 -
RSS
内存随着服务的每个请求而不断增加External Memory
相比用法是显著Heap Memory
External Memory
一旦进程空闲,它就会关闭Total Heap
与Used Heap
受到控制的记忆是很好根据我的理解,Heap 之外的某些东西导致内存上升。
我正在使用sharp node package
它调整大量大图像的大小,最终为这些图像生成巨大的内存缓冲区。
在内存方面,每个请求都提供 10 张图像,最终生成 80 MB 的缓冲区数据
这是我遇到这个 github 问题的地方,讨论了在 NodeJs 中创建缓冲区的影响
这个答案在同一个 github 问题中,解释了缓冲区如何可能占用garbage collector …
我做了一个通过电子邮件ID搜索用户的功能。我正在使用await在异步函数中调用该函数,并将返回值分配给或常量/变量,但在打印常量/变量时变得不确定
function search(email) {
sql = `SELECT email FROM users WHERE email = '${email}'`;
db.query(sql, (err, res) => {
if (err) {
console.log(err);
}
else {
return res[0].email;
}
})
}
const auth = async (req, res, next) => {
try {
const token = req.header('Authorization').replace('Bearer', '');
const decoded = jwt.verify(token, 'catisdoguniversaltruth');
const user = await search(decoded._id);
console.log(user);
if (!user) {
throw new Error();
}
next();
}
catch (e) {
res.status(401).send("Not Authenticated, Please login");
}
};
module.exports = auth;
Run Code Online (Sandbox Code Playgroud) node.js ×4
memory-leaks ×2
sharp ×2
angular ×1
angular8 ×1
buffer ×1
dotenv ×1
httpclient ×1
javascript ×1
promise ×1
typescript ×1