https://github.com/swivelgames/npm-url-utils
Node.js - An implementation of URLUtils as described by MDN. Useful for emulating window.location on the server side.
https://github.com/swivelgames/npm-url-utils
Last synced: 3 months ago
JSON representation
Node.js - An implementation of URLUtils as described by MDN. Useful for emulating window.location on the server side.
- Host: GitHub
- URL: https://github.com/swivelgames/npm-url-utils
- Owner: Swivelgames
- License: unlicense
- Created: 2014-08-12T18:01:55.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-29T04:11:04.000Z (about 10 years ago)
- Last Synced: 2024-04-14T09:44:37.632Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 184 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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)
```bash
npm install url-utils
``````javascript
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"
});
```