Skip to content
← Projects

nrel-spa

JavaScript port of NREL's Solar Position Algorithm, accurate to ±0.0003°.

TypeScriptnpm

About

nrel-spa is a high-precision JavaScript port of NREL's Solar Position Algorithm, accurate to ±0.0003° for any date from the year -2000 to 6000. Zero runtime dependencies. Used for solar energy, architecture, agriculture, and astronomy.

Install

npm install nrel-spa

Quick start

import { getSpa, calcSpa } from 'nrel-spa';

const date = new Date('2025-06-21T00:00:00Z');

// Raw fractional hours
const raw = getSpa(date, 40.7128, -74.006, -4); // New York, EDT
console.log(raw.sunrise, raw.solarNoon, raw.sunset);

// Formatted HH:MM:SS strings
const fmt = calcSpa(date, 40.7128, -74.006, -4);
console.log(fmt.sunrise); // "05:25:03"

Full API and options onGitHub and npm.