End of labyrinth.
TABOR Sebastien authored
75b00c7c

Nuit de l'Info

Getting Started

Requirements

  • Node.Js: Long-Term Support (LTS) version 10.16.3 or more.
  • MongoDB: version 4.2.0 or more.

Installing dependencies

To install all the dependencies, including development dependencies, run the following command:

npm install

To install only the production dependencies, run the following command:

npm install --production

Configuring project

Before running the application, the project has to be configured.

Copy the configuration file config.json to src/config.json, and open the newly created file.

Use the following configuration variable description to configure the project:

Environment

  • env: environment variable (prod or dev).

Logging

  • log.level: logging level (info, warn, or error).

Express settings

  • host: public domain name of the application.
  • port: port to access the application.
  • log: enables access logs.
  • enable_ssl: enables TLS/SSL, certificates have to be set.
  • ssl.key: path to private key file.
  • ssl.cert: path to certificate file.
  • ssl.ca: path to certification authority (CA) file.

MongoDB settings

  • mongodb.host: domain of MongoDB server (can use private domain like localhost).
  • mongodb.port: port of MongoDB server.
  • mongodb.username: username to connect on MongoDB server.
  • mongodb.password: password to connect on MongoDB server.
  • mongodb.database: database to connect on MongoDB server.
  • mongodb.debug: enables MongoDB debugging logs.

Session management settings

  • session.name: name of the session cookie.
  • session.secret: secret to sign session identifiers (must not be empty!).
  • session.cookie.secure: restricts cookie to HTTPS only (SSL has to be set if enabled).
  • session.cookie.httpOnly: restricts cookie to HTTP(S) only (should be enabled for a better security).
  • session.cookie.maxAge: the maximum time the session cookie will be valid (in milliseconds).
  • session.resave: enables saving session after each request no matter session has been altered (not recommended).
  • session.saveUninitialized: enables saving newly created session even if it has not been altered.

Building application

To build typescript, run the following command:

npm run build-tsc

To build webpack (Angular), use one of the following commands:

npm run build-webpack-dev # For development building
npm run build-webpack # For production building

It is also possible to build typescript and webpack (Angular) in one command:

npm run build-dev # For development building
npm run build # For production building

Running the application

To run the application, run the following command:

npm run start

Project main folders

Node Modules (dependencies) folder

Folder node_modules contains all Node.Js module dependencies. It is managed by Node Package Manager (NPM).

This folder MUST NOT be commited on the repository.

Building folder

Folder build is the building folder where typescript files will be built as JavaScript file.

This folder is not (and MUST NOT) be accessible through the HTTP server.

This folder MUST NOT be commited on the repository.

Inside this folder, Node.Js entry point file build/index.js can be found.

Distribution folder

Folder dist is the distribution folder where webpack (Angular) files will be built.

This folder is accessible through the HTTP server, using the path /dist.

This folder MUST NOT be commited on the repository.

Inside this folder, dist/app will contain Angular client-side files.

Public folder

Folder public is the public folder where public files that need to be served are. Put any file that need to be accessible by web-clients inside this folder.

All the content of this folder will be copied in dist folder by webpack, except .scss or .sass files that will be compiled into .css files instead.

This folder MUST NOT contain a public/app sub-folder to not conflict with Angular compiled application.

Source folder

Folder src is the source folder where source files can be found.

This folder is not (and MUST NOT) be accessible through the HTTP server.

This folder is the entry folder for typescript and webpack compilers.

The src/app sub-folder contains client-side Angular files that will be compiled and served through dist/app folder.

Creating a new application

Creating base folders and files

To create a new application, create a new src/app/[APP_NAME] folder that will contain Angular client-side files.

Files also have to be created for HTTP and Socket.io routing inside src/routes:

  • src/routes/[APP_NAME].ts contains HTTP routes (Express).
  • src/routes/[APP_NAME].socket.ts contains Socket.io routes/events.

Angular file naming

Inside src/app, Angular files should follow Angular naming file convention:

  • [MODULE_NAME].module.ts for modules.
  • [MODULE_NAME]-routing.module.ts for module routing.
  • [COMPONENT_NAME].component.(css|html|ts) for components.
  • [SERVICE_NAME].service.ts for services.
  • [DIRECTIVE_NAME].directive.ts for directives.

Creating/Using models

To create or use existing MongoDB models for the application, use mongoose and folder src/models.

Model files should be named src/models/[MODEL_NAME].ts and should be imported in src/models/index.js.

To access the model, load the model using:

let model = mongoose.model('[MODEL_NAME]');