How to do Node.js path aliases?

Viewed 1504

I am using Webpack in order to build my Node.js backend project. In my Webpack config I have aliases, like this:

alias: {
  '@': resolvePath('src'),
  '@app': resolvePath('src/app'),
},

When I build the app for production, those aliases are working, since Webpack converts them to the their real paths on the created bundle.

However I ran nodemon in order to develop the API. And nodemon is not related to the webpack bundle or the devserver. Therefore this is getting error (obviously):

let myService = require('@services/my-service');

I want to ask how to run those aliases using Webpack config OR allow kind of aliases using the nodemon server before a bundle was created - in dev mod.

0 Answers
Related