路徑處理模組

require('path')

規範化字串路徑 .normalize(String)

合併字串路徑 .join(String , String ,...)

解析絕對路徑 .resolve(String)

解析相對路徑 .relative(.resolve_a, .resolve_b)

取得資料夾路徑 .path_resolve(String , String) .dirname(path_resolve)

取得路徑中檔案副檔名

var path = require('path');

var path_b = "test"; var path_c = "test.txt"; var path_resolve = path.resolve(path_b,path_c); console.info(path_resolve); console.info();

console.info(path.extname(path_resolve)); console.info();

取得路徑中最後部分

var path_basename = path.basename(path_resolve, path_extname); console.info(path_basename);

解析與格式化URL路徑

var url = require('url');

var queryUrl = "http://localhost:6666/index?name=king&gender=male&level=high"; console.info(typeof url.parse(queryUrl)); console.info(); var url_parse = url.parse(queryUrl); //使用parse方法 console.info(url_parse) console.info();

var url_format = url.format(url_parse); console.info(url_format); //使用format方法 console.info();

URL路徑轉化

var url = require('url');

console.info(url.resolve('/one/two/three' , 'four')); console.info(url.resolve('/one/two/three/' , 'four')); console.info(url.resolve('/one/two/three' , '/four')); console.info(url.resolve('/one/two/three/' , '/four')); console.info(url.resolve('http://www.exam.com/one','two')); console.info(url.resolve('http://www.exam.com/one','/two')); console.info(url.resolve('http://www.exam.com/one/','two')); console.info(url.resolve('http://www.exam.com/one/','/two'));

URL參數轉化為物件

var url = require('url'); var querystring = require('querystring');

var queryUrl = "http://localhost:6666/index?name=king&gender=male&level=high"

console.info('typeof queryUrl is :' + typeof url.parse(queryUrl)); console.info(); var url_parse = url.parse(queryUrl).query var querystring_parse = querystring.parse(url_parse); console.info(querystring_parse);

results matching ""

    No results matching ""