node.js

来源:互联网 发布:农历快速日柱推算法 编辑:程序博客网 时间:2024/04/28 12:15

在官网下载node.js for mac的安装包,在本地点击安装,默认会安装在/usr/local/bin目录下面有node和npm两个bin文件,即算是安装成功。编写的js文件如果想运行,需要在终端指向对应的目录去执行node xx.js命令。

每次执行js文件。先开启一个服务先

在终端可以直接输入node 会弹出类似mysql的>箭头,即可以输入js代码。并执行。

control+c返回可编辑状态

在node 的命令行状态下输入requier('http')

直接打印

{ parsers:    { name: 'parsers',     constructor: [Function],     max: 1000,     list: [] },  STATUS_CODES:    { '100': 'Continue',     '101': 'Switching Protocols',     '102': 'Processing',     '200': 'OK',     '201': 'Created',     '202': 'Accepted',     '203': 'Non-Authoritative Information',     '204': 'No Content',     '205': 'Reset Content',     '206': 'Partial Content',     '207': 'Multi-Status',     '300': 'Multiple Choices',     '301': 'Moved Permanently',     '302': 'Moved Temporarily',     '303': 'See Other',     '304': 'Not Modified',     '305': 'Use Proxy',     '307': 'Temporary Redirect',     '400': 'Bad Request',     '401': 'Unauthorized',     '402': 'Payment Required',     '403': 'Forbidden',     '404': 'Not Found',     '405': 'Method Not Allowed',     '406': 'Not Acceptable',     '407': 'Proxy Authentication Required',     '408': 'Request Time-out',     '409': 'Conflict',     '410': 'Gone',     '411': 'Length Required',     '412': 'Precondition Failed',     '413': 'Request Entity Too Large',     '414': 'Request-URI Too Large',     '415': 'Unsupported Media Type',     '416': 'Requested Range Not Satisfiable',     '417': 'Expectation Failed',     '418': 'I\'m a teapot',     '422': 'Unprocessable Entity',     '423': 'Locked',     '424': 'Failed Dependency',     '425': 'Unordered Collection',     '426': 'Upgrade Required',     '428': 'Precondition Required',     '429': 'Too Many Requests',     '431': 'Request Header Fields Too Large',     '500': 'Internal Server Error',     '501': 'Not Implemented',     '502': 'Bad Gateway',     '503': 'Service Unavailable',     '504': 'Gateway Time-out',     '505': 'HTTP Version Not Supported',     '506': 'Variant Also Negotiates',     '507': 'Insufficient Storage',     '509': 'Bandwidth Limit Exceeded',     '510': 'Not Extended',     '511': 'Network Authentication Required' },  IncomingMessage:    { [Function: IncomingMessage]     super_:       { [Function: Readable]        ReadableState: [Function: ReadableState],        super_: [Object],        _fromList: [Function: fromList] } },  OutgoingMessage:    { [Function: OutgoingMessage]     super_:       { [Function: Stream]        super_: [Object],        Readable: [Object],        Writable: [Object],        Duplex: [Object],        Transform: [Object],        PassThrough: [Object],        Stream: [Circular] } },  ServerResponse:    { [Function: ServerResponse]     super_: { [Function: OutgoingMessage] super_: [Object] } },  Agent:    { [Function: Agent]     super_: { [Function: EventEmitter] listenerCount: [Function] },     defaultMaxSockets: 5 },  globalAgent:    { domain: null,     _events: { free: [Function] },     _maxListeners: 10,     options: {},     requests: {},     sockets: {},     maxSockets: 5,     createConnection: [Function] },  ClientRequest:    { [Function: ClientRequest]     super_: { [Function: OutgoingMessage] super_: [Object] } },  request: [Function],  get: [Function],  Server: { [Function: Server] super_: { [Function: Server] super_: [Object] } },  createServer: [Function],  _connectionListener: [Function: connectionListener],  Client: [Function: deprecated],  createClient: [Function: deprecated] }

fs目录

> var fs = require('fs');undefined> fs{ Stats: [Function],  exists: [Function],  existsSync: [Function],  readFile: [Function],  readFileSync: [Function],  close: [Function],  closeSync: [Function],  open: [Function],  openSync: [Function],  read: [Function],  readSync: [Function],  write: [Function],  writeSync: [Function],  rename: [Function],  renameSync: [Function],  truncate: [Function],  truncateSync: [Function],  ftruncate: [Function],  ftruncateSync: [Function],  rmdir: [Function],  rmdirSync: [Function],  fdatasync: [Function],  fdatasyncSync: [Function],  fsync: [Function],  fsyncSync: [Function],  mkdir: [Function],  mkdirSync: [Function],  readdir: [Function],  readdirSync: [Function],  fstat: [Function],  lstat: [Function],  stat: [Function],  fstatSync: [Function],  lstatSync: [Function],  statSync: [Function],  readlink: [Function],  readlinkSync: [Function],  symlink: [Function],  symlinkSync: [Function],  link: [Function],  linkSync: [Function],  unlink: [Function],  unlinkSync: [Function],  fchmod: [Function],  fchmodSync: [Function],  lchmod: [Function],  lchmodSync: [Function],  chmod: [Function],  chmodSync: [Function],  lchown: [Function],  lchownSync: [Function],  fchown: [Function],  fchownSync: [Function],  chown: [Function],  chownSync: [Function],  _toUnixTimestamp: [Function: toUnixTimestamp],  utimes: [Function],  utimesSync: [Function],  futimes: [Function],  futimesSync: [Function],  writeFile: [Function],  writeFileSync: [Function],  appendFile: [Function],  appendFileSync: [Function],  watch: [Function],  watchFile: [Function],  unwatchFile: [Function],  realpathSync: [Function: realpathSync],  realpath: [Function: realpath],  createReadStream: [Function],  ReadStream:    { [Function: ReadStream]     super_:       { [Function: Readable]        ReadableState: [Function: ReadableState],        super_: [Object],        _fromList: [Function: fromList] } },  FileReadStream:    { [Function: ReadStream]     super_:       { [Function: Readable]        ReadableState: [Function: ReadableState],        super_: [Object],        _fromList: [Function: fromList] } },  createWriteStream: [Function],  WriteStream:    { [Function: WriteStream]     super_:       { [Function: Writable]        WritableState: [Function: WritableState],        super_: [Object] } },  FileWriteStream:    { [Function: WriteStream]     super_:       { [Function: Writable]        WritableState: [Function: WritableState],        super_: [Object] } },  SyncWriteStream:    { [Function: SyncWriteStream]     super_:       { [Function: Stream]        super_: [Object],        Readable: [Object],        Writable: [Object],        Duplex: [Object],        Transform: [Object],        PassThrough: [Object],        Stream: [Circular] } } }

url

> var url = require('url');undefined> url.purl.propertyIsEnumerable  url.parse                 > url.parse('http:localhost:1337/p/a/t/h?query=string#hash'){ protocol: 'http:',  slashes: null,  auth: null,  host: null,  port: null,  hostname: null,  hash: '#hash',  search: '?query=string',  query: 'query=string',  pathname: 'localhost:1337/p/a/t/h',  path: 'localhost:1337/p/a/t/h?query=string',  href: 'http:localhost:1337/p/a/t/h?query=string#hash' }> 

上面的url逻辑有误,

> url.parse('http://localhost:1337/p/a/t/h?query=string#hash'){ protocol: 'http:',  slashes: true,  auth: null,  host: 'localhost:1337',  port: '1337',  hostname: 'localhost',  hash: '#hash',  search: '?query=string',  query: 'query=string',  pathname: '/p/a/t/h',  path: '/p/a/t/h?query=string',  href: 'http://localhost:1337/p/a/t/h?query=string#hash' }



原创粉丝点击