In this tutorial you will learn how to create a basic web application with FoalTS. The demo application is a simple to-do list with which users can view, create and delete their tasks.
Node.js 8 or greater
First you need to install globaly the Command Line Interface (CLI) of FoalTS. It will help you create a new project and generate files all along your development.
npm install -g @foal/cli
Then create a new application.
foal createapp my-app
This command generates a new directory with the basic structure of the new application. It also installs all the dependencies. Let's look at what
my-app root directory is just a container for your project.
config/ directory contains configuration files for your different environments (production, test, development, e2e, etc).
node_modules/ directory contains all the prod and dev dependencies of your project.
The static files are located in the
src/ directory contains all the source code of the application.
app/ directory includes the components of your server (controllers, services and hooks).
End-to-end tests are located in the
scripts/ folder contains scripts intended to be called from the command line (ex: create-user).
ormconfig.js file defines the configuration and credentials of the database(s) connection(s). They can also be passed through environment variables.
package.json lists the dependencies and commands of the project.
tsconfig.*.json files list the TypeScript compiler configuration for each
Finally the linting configuration can be found in the
Let's verify that the FoalTS project works. Run the following commands:
cd my-appnpm run develop
You've started the development server.
The development server watches at your files and automatically compiles and reloads your code. You don’t need to restart the server each time you make code changes. Note that it is only intended to be used in development, do not use it on production.
Port 3001 already in use?
You can define in
config/default.jsonwhich port the application is using.
Go to http://localhost:3001 in your browser. You should see the text Welcome to the future.
Congratulations, you now have a server running!