I’m trying to import my code functions from one file to another, however, it’s not working.
Look at the file I’m exporting from:
const uri = "mongodb+srv://<User>:<PassWord>@cluster0.ubhacr9.mongodb.net/?retryWrites=true&w=majority"
const client = new MongoClient(uri);
async function run(){
//code
}
async function inserirDatabase(tipo, descricao, valor, id){
//code
}
async function readDatabase (){
//code
}
async function deleteOneOnDatabase(id){
//code
}
module.exports = run, inserirDatabase, readDatabase, deleteOneOnDatabase
Look how I’m importing the file:
import {run, inserirDatabase, readDatabase, deleteOneOnDatabase} from '../database/database.js';
2
Answers
Instead of doing module.exports, try adding "export" before each function name. ie:
Export File:
Import File: