-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
20 lines (13 loc) · 772 Bytes
/
server.js
File metadata and controls
20 lines (13 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const express = require('express'); // accepts is present in express
const useragent = require('express-useragent');
const app = express(); // instantiate the express
app.use(express.static('view'));
app.use(useragent.express()); // instantiating the dependency in express
app.get('/api/whoami', function(req, res){
var ip = req.ip;
var lang = req.acceptsLanguages();
var software = req.useragent; // get user information using useragent dependency
software = software.platform+", "+software.os;
res.json({'ip address' : ip, 'language': lang[0], 'software': software}); // can use /res.send({ipaddress : ip});/ also
});
app.listen(process.env.PORT || 3000);