Advanced

Table of Content

Table of Content

Table of Content

Modules and Imports

Modules and Imports in JavaScript Modules allow JavaScript code to be divided into smaller, reusable files. This improves code maintainability and organization.

This Privacy Policy describes how Alevio ("we,"

"our," or "us"), founded and led by Felix Danyluk (CEO and Founder), collects, uses, and discloses your information when you use our application, website, and services (collectively, the "Service").

Wichtig: Alevio ist als privacy-first Anwendung konzipiert. Alle deine persönlichen Daten werden lokal auf deinem Gerät gespeichert und nicht an unsere Server übertragen, es sei denn, du aktivierst explizit Cloud-Funktionen.

1. Information We Collect

Alevio operates primarily as a local application.

The information stored includes:

• Personal information: name and preferences (stored locally only).

• Usage data: daily responses and insights (stored locally only).

• Device information: app preferences and settings (stored locally only).

• Al Chat data: when using Al features, messages are sent to OpenAl for processing.

2. How We Use Your Information

We use the information we collect to:

• Provide, maintain, and improve our Service.

• Personalize your experience.

• Communicate with you about our Service.

• Monitor and analyze trends, usage, and activities.

3. Sharing Your Information

We may share your information with:

• Service providers who perform services on our behalf.

• Business partners with whom we jointly offer products or services.

• Law enforcement or other third parties when required by law.

4. Data Security

We implement appropriate technical and organizational measures to protect the security of your personal information. However, please note that no method of transmission over the note that no method of transmission over the Internet or method of electronic storage is 100% secure.

5. Your Choices

You can access, update, or delete your account information at any time by logging into your account settings. You may also contact us directly to request access to, correction of, or deletion of any personal information that you have provided to us.

6. Children's Privacy

Our Service is not intended for children under the age of 13. We do not knowingly collect personal information from children under 13. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact us.

7. Changes to This Privacy Policy

We may update our Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on this page.

8. Company Information

Alevio is founded and led by Felix Danyluk, CEO and Founder. Our commitment to privacy and data protection is a core value of our leadership team.

9. Contact Us

If you have any questions about this Privacy Policy, please contact us at privacy.alevio@gmail.com

Exporting in CommonJS

Create a file called math.js:

function add(a, b) {
  return a + b;
}
  
function subtract(a, b) {
  return a - b;
}
  
// Export functions
module.exports = { add, subtract };

Importing in CommonJS

In app.js, import the module using require():

const math = require("./math");

console.log(math.add(5, 3)); // Outputs: 8
console.log(math.subtract(10, 4)); // Outputs: 6

Exporting a Single Value

module.exports = function (name) {
  return `Hello, ${name}!`;
};

Importing a single exported function:

const greet = require("./greet");
console.log(greet("Alice")); // Outputs: Hello, Alice!

ES6 Modules (ESM)

ES6 Modules are the modern way to work with modules in JavaScript. They use export and import and work in both browsers and Node.js (with "type": "module" in package.json).

Named Exports

Create math.js:

export function add(a, b) {
  return a + b;
}
  
export function subtract(a, b) {
  return a - b;
}

Default Exports

Only one default export per file:

export default function multiply(a, b) {
  return a * b;
}

Importing in ES6 Modules

Importing Named Exports

In app.js:

import { add, subtract } from "./math.js";

console.log(add(5, 3)); // Outputs: 8
console.log(subtract(10, 4)); // Outputs: 6

Importing a Default Export

import multiply from "./math.js";
console.log(multiply(4, 5)); // Outputs: 20

Importing Everything from a Module

import * as math from "./math.js";

console.log(math.add(2, 3));
console.log(math.subtract(7, 2));

Using ES6 Modules in Node.js

To use ES6 modules in Node.js, add "type": "module" in package.json:


Then, use import instead of require().

import { add } from "./math.js";
console.log(add(10, 5));

Differences Between CommonJS and ES6 Modules

FeatureCommonJS (require)ES6 Modules (import)Default inNode.jsModern JavaScript (ES6)Syntaxrequire() / module.exportsimport / exportLoad TypeSynchronousAsynchronousCan be used in BrowsersNo (without bundlers)Yes (Supported in modern browsers)

When to Use Which?

  • Use CommonJS for Node.js applications that do not require modern JavaScript syntax.

  • Use ES6 Modules for modern JavaScript projects, browsers, and future-proof development.

Conclusion

Modules improve code reusability and organization. ES6 Modules (import/export) are the standard for modern JavaScript, while CommonJS (require/module.exports) is still widely used in Node.js. The next section will cover working with databases in JavaScript, focusing on connecting Node.js to relational and NoSQL databases.

Create a free website with Framer, the website builder loved by startups, designers and agencies.