cwmsjs v2.4.0-2026.3.16
Hooks are made wrapping CWMSjs using code similar to the React example below.
They also provide variables for you to track the state, progress, and data of the request.
The header on the Groundwork-Water webpage provides a list of currently available hooks.
npm install cwmsjs --save
import { Configuration, ProjectsApi } from "cwmsjs";
const config = new Configuration({
basePath: 'https://cwms-data.usace.army.mil/cwms-data',
});
const projects_api = new ProjectsApi(config);
projects_api
.getProjects({
office: 'SWT',
idMask: 'KEYS*',
pageSize: 5,
})
.then(async (data) => {
console.log(data?.projects);
expect(Array.isArray(data?.projects)).toBe(true);
const firstProject = data?.projects?.[0];
if (firstProject?.location?.name) {
const project = projects_api.getProjectsWithName({
office: 'SWT',
name: firstProject.location.name,
});
console.log(project?.location?.name);
}
console.log(`Returned ${data?.projects?.length ?? 0} projects`);
})
.catch(async (e) => {
if (e.response) {
const error_msg = e.response.json();
e.message = `${e.response.url}\n${e.message}\n${JSON.stringify(
error_msg,
null,
2
)}`;
console.error(e);
throw e;
} else {
throw e;
}
});
curl -O "https://raw.githubusercontent.com/HydrologicEngineeringCenter/cwms-data-api-client-javascript/main/src/dist/bundle.js"
<!-- Include the bundle.js file -->
<script src="./bundle.js"></script>
<!-- Call the cwmsjs after the bundle has loaded -->
<script type="module">
const config = new cwmsjs.Configuration({
basePath: 'https://cwms-data.usace.army.mil/cwms-data',
});
const projects_api = new cwmsjs.ProjectsApi(config);
projects_api
.getProjects({
office: 'SWT',
idMask: 'KEYS*',
pageSize: 5,
})
.then(async (data) => {
console.log(data?.projects);
expect(Array.isArray(data?.projects)).toBe(true);
const firstProject = data?.projects?.[0];
if (firstProject?.location?.name) {
const project = projects_api.getProjectsWithName({
office: 'SWT',
name: firstProject.location.name,
});
console.log(project?.location?.name);
}
console.log(`Returned ${data?.projects?.length ?? 0} projects`);
})
.catch(async (e) => {
if (e.response) {
const error_msg = e.response.json();
e.message = `${e.response.url}\n${e.message}\n${JSON.stringify(
error_msg,
null,
2
)}`;
console.error(e);
throw e;
} else {
throw e;
}
});
</script>
An example for calling the Projects endpoint via CDA in JavaScript
Swagger UI for Endpoints