take note: inside src folder
I want to achieve module aliasing name instead of using require("../../services"), require("../../models").
i want to achieve something like this: require("@services"), require("@models");
How to achieve this on serverless framework with node js without using webpack or babel
There is a way to add alias to your node.js project :
You need to do three things. Add a jsconfig.json file at te root of your project, add _moduleAliases option and the module-alias lib inside your package.json and finally import the lib at the very top of your index.js.
1. Library installation
Run the following command to install the lib :
2. Jsconfig.json
Add a jsconfig.json will help your IDE to detect that you are using aliases. Here is an example of jsconfig.json file :
3. package.json
It is here that the magic happened. In your package.json file add the following lines.
4. Index.js
At the very top of your index.js file add the following code :
This normally should do the trick
If needed, see the documentation here :