Using TypeScript on your POWER web hosting plan

Knowledge Base

Using TypeScript on your POWER web hosting plan


Icons/System/eye-open Created with Sketch. 47 Views 04.02.2021 POWER Web Hosting

Objective

You've subscribed to a Web POWER web hosting plan to deploy Node.js applications, and you want to deploy TypeScript code.

This guide will explain how to do it.

Find out how to install Strapi on your POWER web hosting plan.

Requirements

If you have just started to use your Web POWER web hosting plan, we suggest to have a look at our Getting started with a POWER web hosting plan guide before going further.

Instructions

TypeScript projects can't run directly by our stack, they should be compiled to JS first.

You should include typescript as dev dependency module for your project:

npm add --save-dev typescript

Create a tsconfig.json (if you don't have one already) with the following content for example (see the TypeScript doc for more information):

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "rootDir": "./",
    "outDir": "./build",
    "esModuleInterop": true,
    "strict": true
  }
}

Build the project, either directly with tsc command:

npx tsc  --project ./

or by adding the build script to the package.json:

"scripts": {
  "build": "tsc --project ./"
},

and executing it with npm run build.

Your entrypoint should point to the one in your output dir, for example :

ln -s build/server.js server.js

Go further

Join our community of users on https://community.ovh.com/en/.

Join our Discord on our web-hosting-power channel to discuss directly with the team and other users of this lab.

Related articles