Customizing projects

You can modify some key settings for individual projects by modifying each project’s dfx.json configuration file. You can use the dfx config command to change these settings programmatically or manually edit the dfx.json file directly.

How to change your source directory

Before you compile source code for your project using the dfx build command, you might want to check the default location for storing the source code for your program. By default, the name you use to create a new project is the name used for one data canister (canister_name) and one assets canister (canister_name_assets), and program source code is expected to be in the src/canister_name directory.

Depending on your application’s complexity and architecture, however, you might want to modify the default location for the source code.

For example, for a simple program, you might want to eliminate one directory level and place the source code in the src directory:

  "main": "src/main.mo",

For more complex applications, you might want to use a multi-tiered directory structure:

"canisters": {
  "profiles": {
    "main": "src/profiles/utils/main.mo"
  },
  "events": {
    "main": "src/events/calendar/main.mo"
  },
  "media": {
    "main": "src/events/reports/main.mo"
  }
}
If you modify the default settings for a source code directory, be sure that the settings in the dfx.json configuration file match the directory location on the file system.

How to change the main program file name

Before you compile source code for your project using the dfx build command, you should verify the location and file name used for your program’s source code.

For example, if you want to build a canister for the factorial program and the source code for the program is located in src/math/factorial.mo, you should be sure that you have the correct path specified for the main setting in the canisters section of the configuration file.

For example:

  "canisters": {
    "myFactorial": {
      "main": "src/math/factorial.mo",

Keep in mind that changing the configuration setting for the program file name only affects where the dfx build command looks for the source code to compile. Making changes in the configuration file does not rename any files or directories on the file system. If you change the path to the main program file or the name of the file itself, be sure to change the name and location within your project directory.

How to change the location for serving the application front-end

You can change the default host name and port number for running the local Internet Computer replica processes and serving the application front-end by modifying settings in the dfx.json configuration file.

For example:

    "start": {
      "port": 8000,
      "address": "127.0.0.1",
      "serve_root": "src/hello/public/"