This is the nextfem.js file - a translation of the Python wrapper nextfem.py for the NextFEM REST API into JavaScript/TypeScript.
- REST Wrapper: Modern interface to communicate with NextFEM Designer via REST API
- Async/Await: All operations support JavaScript promises
- Browser and Node.js Support: Compatible with both environments
- Typed Classes: Main classes (
NextFEMrest,vert3)
const { NextFEMrest, vert3 } = require('./nextfem.js');
// Create an instance of the client
const api = new NextFEMrest();
// Example: create a node
(async () => {
const nodeID = await api.addNode(0, 0, 0);
console.log('Node created:', nodeID);
// Create a beam element
const elemID = await api.addBeam('1', '2', 1, 1);
console.log('Beam created:', elemID);
// Run the analysis
const result = await api.RunModel();
console.log('Analysis result:', result);
})();<!DOCTYPE html>
<html>
<head>
<script src="nextfem.js"></script>
</head>
<body>
<script>
const api = new NextFEMrest();
api.addNode(0, 0, 0).then(nodeID => {
console.log('Node created:', nodeID);
});
</script>
</body>
</html>Main client for communicating with NextFEM Designer.
new NextFEMrest(baseUrl, user, msg)baseUrl: REST API URL (default:http://localhost:5151)user: Username (default:"")msg: Show debug messages (default:true)
Model management:
async newModel()- Create a new modelasync openModel(filename)- Open a modelasync saveModel(filename)- Save the modelasync RunModel(outOfProc, noWindow)- Run the analysis
Node and element creation:
async addNode(x, y, z, ...)- Add a nodeasync addNodeWithID(x, y, z, ID)- Add a node with specific IDasync addBeam(n1, n2, sect, mat, sect2)- Add a beam elementasync addBeamWithID(n1, n2, ID, sect, mat, sect2)- Add a beam with IDasync addTruss(n1, n2, sect, mat)- Add a truss elementasync addQuad(n1, n2, n3, n4, sect, mat)- Add a quad elementasync addTria(n1, n2, n3, sect, mat)- Add a triangular element
Sections and materials:
async addRectSection(Lz, Ly)- Add a rectangular sectionasync addCircSection(D)- Add a circular sectionasync addIsoMaterial(name, E, ni, Wden, ...)- Add an isotropic material
Loads:
async addNodalLoad(node, value, direction, loadcase, local)- Add a nodal loadasync addBeamLoadU(elem, value, direction, loadcase, local)- Add a distributed loadasync addLoadCase(name)- Add a load case
Results:
async getBeamForce(num, loadcase, time, type_, station)- Get beam forceasync getBeamForces(num, loadcase, station, time)- Get all forcesasync getNodalDisp(num, loadcase, time, direction)- Get nodal displacementasync getNodalReact(num, loadcase, time, direction)- Get nodal reactionsasync getLoadCases()- Get available load cases
Class to represent a 3D vector.
const v = new vert3(x, y, z);
const coords = v.toDict(); // { num: "0", X: x, Y: y, Z: z }sbool(arg)- Convert "True"/"False" to booleanqt(s)- URL-encode a stringdes(s)- Parse JSON or return string
- Async/Await: All methods are asynchronous and return Promises
- CORS: If you use the browser, make sure NextFEM is configured for CORS
- Errors: Network errors are logged to console
- File system: File operations require Node.js (don't work in browser)
- Use of
async/awaitinstead of synchronous calls fetchAPI instead ofrequests- Methods return Promises instead of direct results
- Native browser support
To add new methods, follow the pattern:
async addNewFeature(param1, param2) {
return await this.nfrest('GET', '/path/to/endpoint/' + String(param1) + '/' + String(param2) + '');
}- ✅ Node.js 12+
- ✅ Chrome, Firefox, Safari, Edge (recent versions)
- ✅ NextFEM Designer with REST API Server enabled