Skip to content

Swivelgames/npm-url-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm-url-utils

Node.js - An implementation of URLUtils as described by MDN. Useful for emulating window.location on the server side.

See MDN documentation: https://developer.mozilla.org/en-US/docs/Web/API/URLUtils

Example (using express.js)

npm install url-utils
app.get('*', function(req, res){
/*>*/	var URLUtils = require('url-utils');
		var window = {
/*>*/		location: new URLUtils(
/*>*/			req.protocol + '://' + req.get('host') + req.originalUrl
/*>*/		)
		};

/*>*/	console.log( window.location.href ); // "http://mywebsite.com/index.jsx?foo=bar#myhash"
/*>*/	console.log( window.location.protocol ); // "http:"
/*>*/	console.log( window.location.hash ); // "#myhash"
});

About

Node.js - An implementation of URLUtils as described by MDN. Useful for emulating window.location on the server side.

Resources

License

Stars

Watchers

Forks

Packages

No packages published