简体   繁体   English

Node.js 内存使用

[英]Nodejs memory usage

I think I have a problem with memory usage.我想我的内存使用有问题。 I have a node.js server :我有一个 node.js 服务器:

var arcadeGames = require('./server/js/arcade');
var cardsGames = require('./server/js/cards');

requires modules that exports object required from .json data需要从.json数据导出所需对象的模块

var http = require('http');
var express = require('express');
var app = express();
var server = http.createServer(app);
//var io = require('socket.io').listen(server);
//var fs = require('fs');

app.get('/specificCategory/:id',function(req,res,next){ 
switch(req.params.id){

    case "Cards":
        console.log(cardsGames.titles);
        break;
    case "Action":
    console.log(actionGames.titles);
    break;
    default:
    console.log("undefined");
}


//var specificCaategory = require('./server/js/'+ req.params.id.toLowerCase());
    //var categoryTitlesAndUrlThumbs = spe
    //console.log(specificCaategory.titles);
})

(both way are working the same commented one or the one with switch) (两种方式都在使用相同的注释或带开关的方式)

the get function is called from browser by clicking the categories ex :Cards, Action and send the request through http, controller from angularjs.通过单击类别(例如:Cards、Action)从浏览器调用 get 函数,并通过 http、来自 angularjs 的控制器发送请求。 The problem is that when I console.log ed out on server first click on each category works fine, but after that, the server takes a lot of time to console.log out the info.(what will happends in browser if this is so hard for server).问题是,当我在服务器上console.log退出时,首先单击每个类别都可以正常工作,但是在那之后,服务器需要很多时间来console.log退出信息。(如果是这样,浏览器中会发生什么服务器很难)。

Have I done something to load the memory so much?我做了什么来加载这么多内存吗?

Add res.end();添加res.end(); after your switch case.在你的开关盒之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM