Creating the application

In this part we are going to create a new Feathers application using the generator. We can install the generator via:

npm install @feathersjs/cli -g

Important: The prerequisites for this guide are the same as the basics prerequisites. This means that Node 8.0.0 (node --version) or later is required.

Generating the application

With everything set up, let's create a directory for our new app:

$ mkdir feathers-chat
$ cd feathers-chat/

Now we can generate the application:

$ feathers generate app

When presented with the project name, just hit enter, or enter a name (no spaces).

Next, write a short description of your application.

The next prompt asking for the source folder can be answered by just hitting enter. This will put all source files into the src/ folder.

The next prompt will ask for the package manager you want to use. The default is the standard npm.

Note: If you choose Yarn instead, make sure it has been installed via npm install yarn -g first.

You're now presented with the option of which transport you want to support. Since we're setting up a real-time and REST API, we'll go with the default REST and options. So just hit enter.

Once you confirm the final prompt, you will see something like this:

Final Configuration

The generated files

Let's have a brief look at the files that have been generated:

  • config/ - Contains the configuration files for the app. production.json files override default.json when in production mode by setting NODE_ENV=production. For details, see the configuration API documentation.
  • node_modules/ - The generator installs the project dependencies either using npm, or yarn. The dependencies are also added in the package.json.
  • public/ - Contains static files to be served. A sample favicon and index.html (which will show up when going directly to the server URL) are already included.
  • src/ - Contains the Feathers server code.
    • hooks/ contains our custom hooks. A simple logger hook for logging debug information about our service calls is already included
    • middleware/ contains any Express middleware
    • services/ contains our services
    • index.js loads and starts the application
    • app.js configures our Feathers application
    • app.hooks.js contains hooks that apply to every service.
    • channels.js sets up Feathers event channels
  • test/ - Contains Mocha test files for the app, hooks and services
    • app.test.js tests that the index page appears, as well as 404 errors for HTML pages and JSON
  • .editorconfig is an EditorConfig setting to help developers define and maintain consistent coding styles among different editors and IDEs.
  • .eslintrc.json contains defaults for linting your code with ESLint.
  • .gitignore - specifies intentionally untracked files which git, GitHub and other similar projects ignore.
  • .npmignore specifies files which are not to be published for distribution.
  • LICENSE - contains the License so that people know how they are permitted to use it, and any restrictions you're placing on it. It defaults to the Feathers license.
  • package.json contains information about our project which npm, yarn and other package managers need to install and use your package.

Running the server and tests

The server can now be started by running

npm start

After that, you can see a welcome page at localhost:3030. When making modifications, remember to stop (CTRL + C) and start the server again.

The app also comes with a set of basic tests which can be run with

npm test

What's next?

We scaffolded a new Feathers application. The next step is to create a service for messages.

Is anything wrong, unclear, missing? Leave a comment or edit this page.

results matching ""

    No results matching ""