Last active
January 1, 2018 08:23
-
-
Save navinthenapster/5a3aff21cca4b6177723a872b8bb99b0 to your computer and use it in GitHub Desktop.
file example for node controller to send the JSON object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GET PARAMETER IN url query (www.google.com?search='hi') | |
exports.weather = function (req, res) { | |
res.setHeader("Access-Control-Allow-Origin", "*"); | |
res.setHeader('Content-Type', 'application/json'); | |
var place= req.query.q; | |
//API Config | |
var url='http://ipapi.co/json'; | |
var request= require('request'); | |
request(url,function(err,response,body){ | |
if(err) | |
res.end(JSON.stringify({code:500, message:"Could not find weather "})); | |
res.end(body); | |
}); | |
}; | |
//GETTING PARAMETER IN URL / (http://localhost:8080/view/2309) | |
exports.block = function (request, response) { | |
response.setHeader("Access-Control-Allow-Origin", "*"); | |
response.setHeader('Content-Type', 'application/json'); | |
var data = request.params.index; | |
response.end(JSON.stringify({ block: web3.eth.getBlock(data) })); | |
}; | |
//GETTING PARAMETER IN POST in body parser ( body parser must be include in server.js ) | |
exports.new_product = function (request, response) { | |
console.log(request.body) | |
response.setHeader("Access-Control-Allow-Origin", "*"); | |
response.setHeader('Content-Type', 'application/json'); | |
var data = request.body; | |
console.log(data.IMEI); | |
response.end(JSON.stringify({ status: true ,code:200 ,message : "data received", data:request.body })) | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment