import export javascript files code example
Example 1: node import all functions from file
function connect() {
}
function closeConnection() {
}
module.exports = {
connect(),
closeConnection()
};
const DbHelper = require ('./utils/dbHelper');
DbHelper.connect();
const { connect, closeConnection } = require ('./utils/dbHelper');
connect();
Example 2: import modules js html
<script type="module" src="main.js"></script>
Example 3: js import and export
export function helloWorld() {
return 'Hello World!';
}
import helloWorld from './helloworld.js';
console.log(helloWorld());