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 the user can view, create and delete his or her 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 (TypeScript files and HTML templates).
app/ directory includes the components of your server (controllers, templates, services, hooks, sub-apps).
End-to-end tests are located in the
scripts/ folder contains scripts intended to be called from the command line (ex: create-user).
ormconfig.json 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 3000 already in use?
You can define in
config/settings.jswhich port the application is using. Simply add the key
"port"with the desired value.
http://localhost:3000 in your browser. You should see the text You have successfully installed FoalTS!.
Congratulations, you now have a server running!