Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2014-8-5: 从输入URL到页面加载完成的过程中都发生了什么事情 | nodejs和express #2

Open
hjzheng opened this issue Aug 7, 2014 · 5 comments

Comments

@hjzheng
Copy link
Owner

hjzheng commented Aug 7, 2014

  1. 从输入 URL 到页面加载完成的过程中都发生了什么事情 (Zhen Ou Yun)
    这是一个可以简单也可以复杂的问题,它没有标准答案,考验回答者知识的广度和深度。有兴趣的同学可以试着回答一下,在看下面链接之前。

    参考
    http://fex.baidu.com/blog/2014/05/what-happen/
    http://www.berlinix.com/net/from-url-input.php

  2. nodejs和express (Hao Ju Zheng)
    在开发CUF项目时候,有时候需要对前端组件进行动态数据测试(数据从后端过来)或这书写Example,例如查询,分页,删除等操作,使用传统服务器端语言,就有点小题大做了。传统服务器端语言,像Java,需要配置struts.xml,书写action,重启tomcat,这些都过于繁琐和低效。

    基于上述背景,决定选用nodejs作为后端服务器, Javascript作为nodejs的语言与前端配合具有其天生的优势:

    • 对JSON数据操作极其容易
    • 丰富的模块和包(express框架可以通过三行code实现一个Ajax请求)
    • 通过包supervisor支持即改即生效

    如何开始nodejs和express之路

    • 安装nodejs

      • 下载安装包(这里以Linux为例)
      • 解压,并将bin目录加入环境变量path中,如果是bash,在.bash_profile中加入下面的code
        PATH=$PATH:/opt/nodejs/node-v0.10.30-linux-x64/bin
      
        export PATH 
      • 重现登陆你的shell
    • 安装express

      • 使用npm安装express和express-generator
        npm install express
      
        npm install -g express-generator
      • 创建express web项目(使用express创建基于ejs模板的项目)
        express -e ./myapp
      • 安装依赖
        npm install
        npm start
    • 写一个的ajax请求

      • 修改routes/users.js
        router.get('/', function(req, res) {
          res.setHeader('Content-Type', 'application/json;charset=utf-8');
          res.send({id: 1, username: 'hjzheng', password: 'hjzheng'});
        });
    • 对应的目录有写好的CRUD ajax请求模板,有兴趣的同学可以参考一下

@hjzheng hjzheng changed the title 2014-8-5: 从输入URL到页面加载完成的过程中都发生了什么事情 2014-8-5: 从输入URL到页面加载完成的过程中都发生了什么事情, nodejs和express Aug 29, 2014
@hjzheng hjzheng changed the title 2014-8-5: 从输入URL到页面加载完成的过程中都发生了什么事情, nodejs和express 2014-8-5: 从输入URL到页面加载完成的过程中都发生了什么事情 | nodejs和express Aug 29, 2014
@hjzheng
Copy link
Owner Author

hjzheng commented Aug 29, 2014

赠送一套nodeJS教程

@hjzheng
Copy link
Owner Author

hjzheng commented Oct 20, 2014

nodejs调试工具

  • supervior 修改文件,无需重启
   #调试express项目
   supervisor  ./bin/www
  • node-inspector 调试JS
  ###node设置debug端口###
  [root@hjzheng markdown-reader]#  node --debug-brk  app.js
  debugger listening on port 5858

  ###node-inspector打开chrome连接端口###
  [root@hjzheng markdown-reader]# node-inspector --web-port=8899 app.js 
  Node Inspector v0.7.4
  Visit http://127.0.0.1:8899/debug?port=5858 to start debugging.

  ###用chrome打开url: http://127.0.0.1:8899/debug?port=5858###
  • forever
    forever让nodejs应用后台执行

@zc0315
Copy link

zc0315 commented Apr 21, 2015

#nodejs的做服务器并发性怎么样?

@hjzheng
Copy link
Owner Author

hjzheng commented Apr 22, 2015

@zc0315 这个我还真没试过,但是用过的人普遍认为还是不错的!

@hjzheng
Copy link
Owner Author

hjzheng commented Jul 31, 2015

forever的替代品 PM2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants