Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Dark Sky serverless function for Netlify
const fetch = require('node-fetch');
exports.handler = async (event, context) => {
try{
const latitude = event.queryStringParameters.latitude;
const longitude = event.queryStringParameters.longitude;
const response = await fetch(`https://api.darksky.net/forecast/${process.env.DARK_SKY_KEY}/${latitude},${longitude}`);
const data = await response.json();
return {
statusCode: 200,
body: JSON.stringify(data)
};
} catch (err) {
return {
statusCode: 500,
body: err.toString()
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.