In this tutorial you will learn how to create a basic web application with FoalTS and MongoDB. The demo application is a simple to-do list with which users can view, create and delete their tasks.
Node.js 8 or greater
Create a New Project
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. Don't forget the --mongodb option.
foal createapp my-app --mongodb
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/ config/ node_modules/ public/ src/ app/ e2e/ scripts/ package.json tsconfig.*.json tslint.json
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).
- The inner
app/directory includes the components of your server (controllers, templates, services, hooks, sub-apps).
- End-to-end tests are located in the
- The inner
scripts/folder contains scripts intended to be called from the command line (ex: create-user).
- The inner
package.jsonlists the dependencies and commands of the project.
tsconfig.*.jsonfiles list the TypeScript compiler configuration for each
- Finally the linting configuration can be found in the
Start The Server
Let's verify that the FoalTS project works. Run the following commands:
cd my-app npm 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.
http://localhost:3001 in your browser. You should see the text Welcome to the future <3.
Congratulations, you now have a server running!