Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

module-alias

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-alias

Create aliases of directories and register custom module paths

  • 2.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
decreased by-13.15%
Maintainers
2
Weekly downloads
 
Created

What is module-alias?

The module-alias package is used to create aliases of directory paths, allowing you to simplify the require/import statements in your Node.js projects. This can be particularly useful for projects with deep directory structures, making the code cleaner and easier to maintain.

What are module-alias's main functionalities?

Registering Aliases

This feature allows you to register aliases for directories so that you can require modules using the alias instead of relative paths.

require('module-alias/register');
moduleAlias.addAliases({
  '@root'      : __dirname,
  '@models'    : __dirname + '/models',
  '@controllers': __dirname + '/controllers',
  '@lib'       : __dirname + '/lib'
});

Customizing Aliases with package.json

You can also define aliases directly in your package.json file, which module-alias will read and use to resolve modules.

{
  "_moduleAliases": {
    "@root": ".",
    "@models": "./models",
    "@controllers": "./controllers",
    "@lib": "./lib"
  }
}

Requiring Modules with Aliases

Once aliases are set up, you can require modules using the defined aliases, making the require statements much cleaner and easier to understand.

const User = require('@models/user');

Other packages similar to module-alias

Keywords

FAQs

Package last updated on 03 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc