如何在大型应用程序中运行Node.js代码?

时间:2014-01-09 04:19:21

标签: node.js

我准备了一个独立的Node.js文件(如下所示)。它按预期工作。当我运行代码时,我在DOS窗口中发出命令 - C:...... \ folder_name> node file_name.js 。在服务器正在侦听时,我在浏览器地址栏中输入了一个URL。完成测试后,我使用CTRL + C手动终止Node.js代码。

现在,我必须在一个大项目/应用程序中做同样的事情。而我迷失了。我不知道它是如何运作的:

  1. 要运行大项目/应用程序,我们只需在浏览器地址栏中输入一个URL即可。我们不在DOS窗口中给出命令,例如 node file_name.js

  2. 大项目/应用程序在WebLogic服务器上运行,其端口是7171.在我的独立Node.js代码中,我定义了一个服务器,它在8080上监听。

  3. 要运行大型项目/应用程序,我不会手动终止特定文件。

  4. 请帮忙。非常感谢你。

    var http= require('http'),
        url = require('url'), 
        server;
    
    server = http.createServer(function(req, res){
        var path = url.parse(req.url).pathname;
    
        switch (path){
    
               case '/lens/v1/ping':
                   res.writeHead(200, {'Content-Type': 'text/plain'});
                   res.write('The lens route works!\n');
                   res.end();
    
               case '/ecrud/v1/core/ping':
                   res.writeHead(200, {'Content-Type': 'text/plain'});
                   res.write('The ecrud route works!\n');
                   res.end();
    
               break;
    
               default: send404(res);
           }
    }); 
    
    send404 = function(res){
        res.writeHead(404);
        res.write('Status 404');
        res.end();
    };
    
    server.listen(8080);
    

0 个答案:

没有答案