zoukankan      html  css  js  c++  java
  • nodejs的初学

    1.启服务器。先server.js,再命令行输入命令node server.js,打开浏览器输入http://127.0.0.1:2016可以看到有内容输出.

    server.js代码如下:

    var http = require('http')

    var server=http.createServer(function(req,res){
    res.writeHead(200,{'Content-Type':'text/plain'})
    res.write('Hello Nodejs ')
    res.end('|||')
    })
    server.listen(2016,'127.0.0.1')
    console.log('server running at http://127.0.0.1:2016/')

    2.模块与包管理

    javascript缺少模块管理。commonjs规范和nodejs.

    nodejs,每个文件就是一个独立模块,不用担心变量污染,方法的隔离等。

     3.node.js中的path.join方法使用说明:path.join([path1], [path2], [...]),该方法将多个参数值字符串结合成一个路径字符串

    使用前需要引入path模块(var path= require(“path”) ), path.join(__dirname, '/dist')

    path.resolve方法使用说明path.resolve([from ...], to),将参数 to 位置的字符解析到一个绝对路径里。

    如path.resolve(__dirname, 'dist') ,

    dirname方法
    该方法用于获取一个路径中的目录名,使用方式如下:
    该方法使用一个参数,参数为一个路径可以是相对路径,绝对路径,可以为一个目录的路径,也可以为一个文件的路径。当参数值为目录路径时,该方法返回该目录的上层目录;当参数值为文件路径时,该方法返回该文件所在的目录。
    var dirname = path.dirname("./a/b");
    console.log(dirname);      //   .a
     
    参考:http://www.cnblogs.com/duhuo/p/4752640.html
     
    4.参考视频
    https://www.infoq.com/presentations/Parallel-Programming-with-Nodejs?utm_source=jobboleblog
     

    参考这篇文章《学习JavaScript的在线课程和指南

    http://blog.jobbole.com/73465/?utm_source=jobboleblog

    慕课网:http://www.imooc.com/video/1084

    github:https://github.com/Encn/node

    网友总结大全

    http://www.cnblogs.com/vman/p/4799289.html

  • 相关阅读:
    Bit Manipulation
    218. The Skyline Problem
    Template : Two Pointers & Hash -> String process
    239. Sliding Window Maximum
    159. Longest Substring with At Most Two Distinct Characters
    3. Longest Substring Without Repeating Characters
    137. Single Number II
    142. Linked List Cycle II
    41. First Missing Positive
    260. Single Number III
  • 原文地址:https://www.cnblogs.com/alice-fee/p/6159615.html
Copyright © 2011-2022 走看看