node import all functions from file
//we are in ./utils/dbHelper.js, here we have some helper functions
function connect() {
// connect do db...
}
function closeConnection() {
// close connection to DB...
}
//let's export this function to show them to the world outside
module.exports = {
connect(),
closeConnection()
};
// now we are in ./main.js and we want use helper functions from dbHelper.js
const DbHelper = require ('./utils/dbHelper'); // import all file and name it DbHelper
DbHelper.connect(); // use function from './utils/dbHelper' using dot(.)
// or we can import only chosen function(s)
const { connect, closeConnection } = require ('./utils/dbHelper');
connect(); // use function from class without dot
Also in JavaScript:
- push values to state array class react
- javascript reduce method stack overflow
- js copy array
- angular delete from array by name
- string includes substring javascript
- ngfor on keys of a dictionary angular
- make nextjs project
- ng-class equivalent in react
- generate random password
- get an html img tag from a string
- react native conditional rendering
- ngmodel div angular 7
- jquery enable disable textbox
- passportjs mac req.user not saved
- Xbonacci
- javascript onclick
- json property becoming small after retriving from .net core controller
- ajouter un lien href dans du javascript
- how to read environment variable in node js
- settimeout js
- angular 9 change menu link item at runtime
- javascript json decode
- How to get unix timestamp from tomorrow nodejs
- binary gap