export.create
In Web Programming the export.create is used for making a function, variable, or module available for use in other parts of the program. Using this, we can properly modularize the code by exporting a specific function that is responsible for creating or initializing the objects.
Syntax:
exports.create = (data) => {
// data or perform some action
};
Project Structure:
Example: In the below example, we have created the module.js module that exports the create function and in the app.js we are importing this module and using the create function to print the square of the given number.
Javascript
// module.js exports.create = (n) => { const res = n * n; return res; }; |
Javascript
// app.js const { create } = require( './module' ); // using the create function const num = 5; const res = create(num); console.log(`The square of ${num} is: ${res}`) |
Output:
What is the difference between export.create and router.post?
export.create
and router.post
are used in the context of backend frameworks like Express JS. They both are used for handling HTTP requests and operate at different levels within the framework. In this article we will learn about export.create and router.post and see the key differences between them.