The problem is that you're replacing the exports property twice:
module.exports = new a();
module.exports = new b();
As a result, you're only exporting one thing: an instance of b, which has no method1 on it.
Instead, write to properties on the exports object:
module.exports.a = new a();
module.exports.b = new b();
Then:
const x = require('./file.js');
x.a.method1();
// ...
or more typically, with destructuring so you don't need x:
const {a, b} = require('./file.js');
a.method1();
// ...
All of that said: That syntax is the old CommonJS module system. I suggest you learn the newer standard syntax, "ESM" (ECMAScript Modules), added to the JavaScript specification in ES2015:
function A() {
}
A.prototype.method1 = function() { /* ... */ };
A.prototype.method2 = function() { /* ... */ };
function B(){}
B.prototype.method3 = function() { /* ... */ };
B.prototype.method4 = function() { /* ... */ };
export const a = new A();
export const b = new B();
Also note that I've made the constructor functions start with a capital letter, which is the standard convention in JavaScript.
The import would be:
import { a, b } from "./file.js";
a.method1();
// ...
To do that, you add "type": :"module" to your package.json (or use the .mjs file extension, see the linked docs for details). Note though that a large number of npm packages haven't been updated to support ESM yet (not least because supporting both took a while to nail down and is a bit of a pain), so in some cases you have to jump through some (minor) hoops to use them; more here.
(You might also look at the class syntax, which provides a more concise and powerful way to write constructor functions and their associated .prototype objects.)