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
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 -gfirst.
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 Socket.io options. So just hit enter.
Once you confirm the final prompt, you will see something like this:
The generated files
Let's have a brief look at the files that have been generated:
config/- Contains the configuration files for the app.
default.jsonwhen 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
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
loggerhook for logging debug information about our service calls is already included
middleware/contains any Express middleware
services/contains our services
index.jsloads and starts the application
app.jsconfigures our Feathers application
app.hooks.jscontains hooks that apply to every service.
channels.jssets up Feathers event channels
test/- Contains Mocha test files for the app, hooks and services
app.test.jstests that the index page appears, as well as 404 errors for HTML pages and JSON
.editorconfigis an EditorConfig setting to help developers define and maintain consistent coding styles among different editors and IDEs.
.eslintrc.jsoncontains defaults for linting your code with ESLint.
.gitignore- specifies intentionally untracked files which git, GitHub and other similar projects ignore.
.npmignorespecifies 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.jsoncontains 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
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
We scaffolded a new Feathers application. The next step is to create a service for messages.