`
sillycat
  • 浏览: 2542365 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

NodeJS Version Upgrade 5.1.0 and Error Handling

 
阅读更多
NodeJS Version Upgrade 5.1.0 and Error Handling

1 Version Upgrade
4.2.2 on Local Mac OS
https://nodejs.org/dist/v4.2.2/

I like to build all these things on my own server. Download the source version.
> wget https://nodejs.org/dist/v4.2.2/node-v4.2.2.tar.gz

> ./configure --prefix=/Users/carl/tool/node-v4.2.2

Make and make install there. Add it to the class path.

5.1.0 on Local Mac OS
https://nodejs.org/dist/v5.1.0/

> wget https://nodejs.org/dist/v5.1.0/node-v5.1.0.tar.gz

> ./configure --prefix=/Users/carl/tool/node-v5.1.0

Do the same thing as 4.2.2.
> node --version && npm --version
v5.1.0
3.3.12

5.1.0 on CentOS/Linux
Prepare the build env
> sudo yum groupinstall "Development Tools"

Same thing as on MAC

Add things to the path as follow:
>vi ~/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin

JAVA_HOME=/opt/jdk1.8.0_60
export JAVA_HOME

JRE_HOME=/opt/jdk1.8.0_60/jre
export JRE_HOME

PATH=$PATH:/opt/jdk1.8.0_60/bin:/opt/jdk1.8.0_60/jre/bin
PATH=$PATH:/opt/sbt/bin
PATH=$PATH:/opt/node/bin

export PATH

Done
> node --version && npm --version
v5.1.0
3.3.12

5.1.0 on Ubuntu System
Same as on MAC OS

5.1.0 on RaspberryPi
Currently version is as follow:
> node --version && npm --version
v0.12.7
2.11.3

Check OS version
> uname -a
Linux raspberrypi1 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015 armv6l GNU/Linux

> uname -a
Linux raspberrypi2 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux

Oh, my different raspberryPis are different.
On ARMV61
> wget https://nodejs.org/dist/v5.1.0/node-v5.1.0-linux-armv6l.tar.gz

Put it in the working directory
> mv node-v5.1.0-linux-armv6l ~/tool/node-v5.1.0

> sudo ln -s /home/carl/tool/node-v5.1.0 /opt/node-v5.1.0

> sudo ln -s /opt/node-v5.1.0 /opt/node

Add that node to the path, then check the version
> node --version && npm --version
v5.1.0
3.3.12

On ARMV71
> wget https://nodejs.org/dist/v5.1.0/node-v5.1.0-linux-armv7l.tar.gz

Same thing as On ARMV61
> node --version && npm --version
v5.1.0
3.3.12

2 Error Handling

For example:
/*jslint node: true */
'use strict';

var ContextIO = require('contextio');
var HashMap = require('hashmap').HashMap;
var _ = require('../underscore');

var services = null;
var cxtioClient = null;
var jobsFilter = null;
var resumesFilter = null;

module.exports = {
    init: init,
    fetchEmailsWithFilter: fetchEmailsWithFilter,
    fetchAttachmentLink: fetchAttachmentLink,
    fetchMailContent: fetchMailContent,
    fetchResumesByAccountCode: fetchResumesByAccountCode,
    fetchJobsByAccountCode: fetchJobsByAccountCode,
    fetchAccountInfoByEmail: fetchAccountInfoByEmail
};

function init(myServices) {
    services = myServices;

    var logger = services.get('logger');
    var config = services.get('config');

    logger.info("EmailScan - initConnection ---------------");
    logger.info(config.data.contextio);

    cxtioClient = new ContextIO.Client(config.data.contextio.version, config.data.contextio.endpoint, config.data.contextio.security);
    jobsFilter = config.data.contextio.jobsFilter;
    resumesFilter = config.data.contextio.resumesFilter;
    //todo: log this twice?
    logger.info("EmailScan - initConnection ---------------");
}

function fetchEmailsWithFilter(accountCode, filter, callback) {
    var logger = services.get('logger');

    logger.trace("EmailScan - fetchEmailsWithFilter - accountCode = " + accountCode);
    logger.trace("EmailScan - fetchEmailsWithFilter - filter = " + JSON.stringify(filter));

    cxtioClient
        .accounts(accountCode)
        .messages()
        .get(filter, function (err, data) {
            if (err) {
                logger.error("EmailScan - fetchEmailsWithFilter - fail to fetch the messages.");
                callback(err, []);
                return;
            }

            if (!data) {
                var warning_message = "EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter);
                logger.warn(warning_message);
                callback(null, []);
            }

            if (data.statusCode !== 200) {
                handleNotOk(data, logger, callback);
                return;
            }

            var msgBody = data.body;
            logger.trace("EmailScan - fetchEmailsWithFilter - get the messages info with filter = " + JSON.stringify(filter));
            logger.trace("EmailScan - fetchEmailsWithFilter - get response info = " + JSON.stringify(data));
            logger.trace("EmailScan - fetchEmailsWithFilter - get message body = " + JSON.stringify(msgBody));

            if (msgBody.length < 1) {
                var warning_msg = "EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter);
                logger.warn(warning_msg);
                callback(null, []);
                return;
            }

            callback(null, msgBody);
        });
}

function handleNotOk (data, logger, callback) {
    //error handle, handle the error
    logger.error("Unsuccessful response handle " + JSON.stringify(data));
    var statusCode = 500;
    if (data.statusCode !== undefined) {
        statusCode = data.statusCode;
    }
    var err_obj = {"statusCode": statusCode, "message": data.body};
    callback(err_obj, null);
}

I like the idea that my colleague change the exports part. Error Handling on the express.io controller
/*jslint node: true */
'use strict';

var HashMap = require('hashmap').HashMap;

var    services = null;

module.exports = {

    getAccountByEmail : function(req, res) {
        //services
        var emailscan = services.get('emailscan');
        var logger = services.get('logger');

        //params
        var email = req.params.email;

        emailscan.fetchAccountInfoByEmail(email, function(err, account){
            if(err){
                res.status(err.statusCode).json(err.message);
                return ;
            }

            if(account === undefined || account === null){
                res.status(404).json({ "type":"error", "value":"The email[" + email + "] is not valid!"});
                return ;
            }

            logger.debug("account info = " + account.id);
            res.json(account);
            return ;
        });
    },

    init : function(myservices){
        services = myservices;
    }

};

References:
http://sillycat.iteye.com/blog/2256088
分享到:
评论

相关推荐

    rh-nodejs6-nodejs-error-ex-1.2.0-6.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    rh-nodejs8-nodejs-error-ex-1.2.0-7.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    rh-nodejs6-nodejs-error-ex-1.2.0-7.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    nodejs npm错误Error:UNKNOWN:unknown error,mkdir 'D:\Develop\nodejs\node_global'at Error

    今天小编就为大家分享一篇关于nodejs npm错误Error:UNKNOWN:unknown error,mkdir 'D:Developnodejsnode_global'at Error,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看...

    nodejs.pdf nodejs初级教程 nodejs初级教程

    nodejs初级教程

    nodejs14.9.0

    nodejs14.9.0

    Nodejs版本管理器(nvm安装包)

    Nodejs版本管理器(nvm安装包)

    node-v10.1.0.pkg

    nodejs -v 10.1.0 for mac ,稳定版本

    nodejs:NodeJS示例项目

    节点js NodeJS示例项目

    NodeJS学习笔记和代码

    NodeJS是一种基于Chrome V8引擎的JavaScript运行环境,它允许开发者在服务器端使用JavaScript进行编程。这个"NodeJS学习笔记和代码"的压缩包显然包含了帮助初学者掌握NodeJS基础知识和实践技能的所有必要资料。 ...

    nodejs oauth 2 例子代码

    nodejs 搭建oauth服务器的代码 Install nodejs and npm and then, simply run npm install and npm start. The server should now be running at http://localhost:3000.

    nodejs 客户端音乐播放器

    player.on('error', (err) =&gt; console.error('An error occurred:', err)); ``` ### 进阶功能 - **音乐库管理**: 可以扩展播放器,使其支持音乐库管理,包括搜索、排序、播放列表等功能。 - **界面集成**: 将...

    NodeJS整理手册文档

    NodeJS是一种基于Chrome V8引擎的JavaScript运行环境,它允许开发者在服务器端使用JavaScript进行编程,从而打破了JavaScript只能在浏览器中运行的传统。本"NodeJS整理手册文档"旨在为对NodeJS感兴趣的朋友们提供一...

    NodeJS开发指南_nodejs开发指南_

    NodeJS是一种基于Chrome V8引擎的JavaScript运行环境,它允许开发者使用JavaScript进行服务器端编程,打破了JavaScript只能在浏览器中运行的传统。本指南将深入探讨NodeJS的核心概念、开发工具、模块系统、网络编程...

    Idea 配置前端web nodejs项目

    Idea 配置前端 Web Nodejs 项目 Idea 配置前端 Web Nodejs 项目是指在 IntelliJ IDEA 集成开发环境中配置 Nodejs 项目的步骤。下面我们将详细讲解配置的步骤和相关知识点。 Idea 配置 Nodejs 项目 首先,我们需要...

    NodeJs技术经典文档

    资源名称:NodeJs技术经典文档资源目录:【】Node.js开发指南_中文正版【】nodejs开发指南pdf及源码及win安装程序【】nodejs手册中文【】NodeJs教程【】umav4simple【】七天学会NodeJS【】七天学会NodeJS【】深入浅...

    nodejs视频教程百度网盘

    nodejs视频教程,可以快速帮助你入门nodejs开发中,nodejs不错哦

    NodeJS 安装包

    NodeJS 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,它让开发者能够在服务器端使用 JavaScript 进行编程,极大地推动了全栈开发的流行。NodeJS 的设计思想是事件驱动、非阻塞 I/O 模型,这使得它在处理高并发...

    NodeJS中文文档精编.pdf 全文免费

    NodeJS中文文档精编.pdf 全文免费 NodeJS是 JavaScript 运行时环境,可以让 JavaScript 代码在服务器端执行。NodeJS 实际上是对 ES 标准的一个实现,同时 Node 也是一个 JS 引擎。 Node 只对 ES 标准进行了实现,...

Global site tag (gtag.js) - Google Analytics