user3686652
user3686652

Reputation: 815

expressjs configuration for ES6 file structure

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

Answers (1)

Robert Fent
Robert Fent

Reputation: 203

You can import a class in the ES6 style with:

import NewClass from 'src/aclass';

const newClass = new NewClass();

Upvotes: 2

Related Questions