index.js Code:
// 1. Create a project // npm -y represents the init program Settings Default // 2. Start project // default startup index.js the Node / nodemon index.js // npm start package.json RUN dev file. script option to add "dev": "the Node index.js" // 3. Installation project dependencies (third-party packages) // npm install Module --save // built-in objects the let HTTP = The require ( 'HTTP' ) // third party plug the let Request = The require ( 'Request' ) // custom plug- // create directories and module js file ./custom_modules/customurlparse.js // introduction module the let customUrlParse = The require ( './ custom_modules / customurlparse.js' ) the let serverHttp.createServer = ((REQ, RES) => { the let urlObj = customUrlParse.parse (req.url) IF (urlObj.pathname == '/index.html' || urlObj.pathname == '/' ) { the let urlStr = `HTTPS: // www.baidu.com /` // imitation phishing site, the server acts as a client requests the server Baidu request.GET (urlStr, (ERR, Data, body) => { // the return to the body member my front end res.end (body) }) } }). the listen ( 8888)
customurlparse.js Code:
// custom modules, export objects // custom url analysis target, modeled node module built url module.exports = { Data: "Data-Test" , the parse: (STR) => { return { pathname: str.split ( "?") [0] str.split () [0]? "?": null , Query: str.split ( ) [1] str.split () [1] '?'? '?': null , Search: str.split ( '?') [. 1] + str.split ( '?') [. 1]? '?': null , path: STR, the href: STR } } }