0

I have 2 different projects which have some common functions.

  • Project 1 : Authentication + api 1 (express but not important)
  • Project 2 : Api 2 (express)

Is it possible to export Authentication function from Project 1 and use it in Project 2 ?

I tried to make a basic package but : If the Projet 1 is a module, I can't start api. If it's not, I can't import function in Project 2

Basically I want something like :

Project 1 :

  • function.ts
export default function foo() {
   if (Html.isProgrammingLanguage()) return 'Boooooo';
   return 'Aha yes';
}
  • index.ts
import foo from './function.ts';
// express things
router.use('/', () => {
   foo();
});

Project 2 :

  • package.json
{
   "dependencies": {
      "project1": "<my git link>"
   }
}
  • index.ts
import foo from 'project1';

// other express things

router.use('/', () => {
   foo();
});

Thank you in advance for your help

Christophe.S
  • 1
  • 1
  • 2
  • How about sperating the Authentication function into a third project and import into both? – Cheng Dicky Jan 18 '22 at 08:01
  • @ChengDicky I thought about it but it force me to separate the Sequelize part and the api for 1 authentication function, i find this solution too heavy for this little problem. Before I find another solution I just call the authentication api by http request, it's not most efficient but it work ! – Christophe.S Jan 18 '22 at 09:40

0 Answers0