Reputation: 6542
In my NODEjs ( using Express ) application, I want to use Country Code inside routes.js but I am unable to access localstorage inside the routes.js
Please provide some solution.
Upvotes: 0
Views: 415
Reputation: 11305
LocalStorage
is only available in browsers on the Window
object.
The Window
object is not available server side.
Following your comment, you could implement a route in your express application which takes the IP as part of the body.
For this to work you will need body-parser
middleware. Example application:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var server;
app.use(bodyParser.json());
app.get('/api/ip', function (req, res) {
res.send(req.body.ip);
});
server = app.listen(3000);
This would return the posted IP.
Upvotes: 1