Express.js/TypeScript Rest API integrating with suncalc for accessing the ☀️'s data based on location and time.
# install dependencies
$ pnpm run install
# run server
$ pnpm run dev
# build module
$ pnpm run build
The SunCalc REST API is described below.
GET /api/position/:date/:latitude,:longitude
curl --request GET \
--url 'http://localhost:8081/api/position/2023-11-13/34.0549,-118.2426'
{
"azimuth": -1.198657687136746,
"altitude": -0.010485801748684758
}GET /api/position/now/:latitude,:longitude
curl --request GET \
--url 'http://localhost:8081/api/position/now/34.0549,-118.2426'
{
"azimuth": -1.198657687136746,
"altitude": -0.010485801748684758
}GET /api/times/2023-11-13/:latitude,:longitude
curl --request GET \
--url 'http://localhost:8081/api/times/2023-11-13/34.0549,-118.2426'
{
"solarNoon": "2023-11-13T19:38:37.667Z",
"nadir": "2023-11-13T07:38:37.667Z",
"sunrise": "2023-11-13T14:24:53.049Z",
"sunset": "2023-11-14T00:52:22.285Z",
"sunriseEnd": "2023-11-13T14:27:38.907Z",
"sunsetStart": "2023-11-14T00:49:36.427Z",
"dawn": "2023-11-13T13:58:25.730Z",
"dusk": "2023-11-14T01:18:49.604Z",
"nauticalDawn": "2023-11-13T13:28:20.400Z",
"nauticalDusk": "2023-11-14T01:48:54.935Z",
"nightEnd": "2023-11-13T12:58:44.641Z",
"night": "2023-11-14T02:18:30.693Z",
"goldenHourEnd": "2023-11-13T15:00:57.040Z",
"goldenHour": "2023-11-14T00:16:18.294Z"
}GET /api/times/now/:latitude,:longitude
curl --request GET \
--url 'http://localhost:8081/api/times/now/34.0549,-118.2426'
{
"solarNoon": "2023-11-13T19:38:37.667Z",
"nadir": "2023-11-13T07:38:37.667Z",
"sunrise": "2023-11-13T14:24:53.049Z",
"sunset": "2023-11-14T00:52:22.285Z",
"sunriseEnd": "2023-11-13T14:27:38.907Z",
"sunsetStart": "2023-11-14T00:49:36.427Z",
"dawn": "2023-11-13T13:58:25.730Z",
"dusk": "2023-11-14T01:18:49.604Z",
"nauticalDawn": "2023-11-13T13:28:20.400Z",
"nauticalDusk": "2023-11-14T01:48:54.935Z",
"nightEnd": "2023-11-13T12:58:44.641Z",
"night": "2023-11-14T02:18:30.693Z",
"goldenHourEnd": "2023-11-13T15:00:57.040Z",
"goldenHour": "2023-11-14T00:16:18.294Z"
}type TimeTypes =
'solarNoon'|
'nadir'|
'sunrise'|
'sunset'|
'sunriseEnd'|
'sunsetStart'|
'dawn'|
'dusk'|
'nauticalDawn'|
'nauticalDusk'|
'nightEnd'|
'night'|
'goldenHourEnd'|
'goldenHour'GET /api/times/2023-11-13/:latitude,:longitude?type=:timeType
curl --request GET \
--url 'http://localhost:8081/api/times/2023-11-13/34.0549,-118.2426?type=sunrise'
{
"sunrise": "2023-11-13T14:24:53.049Z"
}