Reputation: 815
I have created the files
- index.html
- main.js
- server.js
- src/aclass.js
in root folder.The configuration for expressjs is,
app.use(express.static(path.join(__dirname, 'src')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
In Classfile,
class NewClass {
constructor () {}
list() {
return {
'name': 'aName',
'age': 30
}
}
}
export default NewClass;
Here, how to import the class to mainjs file and how to configure the mainjs file in expressjs.
Upvotes: 1
Views: 235
Reputation: 203
You can import a class in the ES6 style with:
import NewClass from 'src/aclass';
const newClass = new NewClass();
Upvotes: 2