Deploying TypeScript to Cloud Foundry

It can be a joy to switch from JavaScript to TypeScript for both backend or frontend JavaScript. I love all the help the VS Code editor gives me from the static typing of many npm libraries. I also love the fast failure from tsc -w (watch files and compile them when they change) when I get confused about the nature/type of an object being passed around.

Remember: TypeScript itself isn’t something you run. Instead it is the generated JavaScript that you run – either upon Node.JS in the backend or your browser’s JavaScript engine in the frontend.

cf-sample-nodejs

To help you convert your backend Node.JS application to TypeScript I’ve converted an old sample application into TypeScript and documented some of the setup steps for your own project.

See https://github.com/drnic/cf-sample-app-nodejs-typescript

This project includes a tsconfig.json file to describe the options I like. Download it and run tsc it will convert the TypeScript src/**/*.ts files into JavaScript built/**/*.js files.

The manifest.yml delegates the start command to npm run-script start, which can be found in package.json running node built/server.js:

  "scripts": {
    "build": "tsc",
    "start": "node built/server.js"
  },

Spread the word

twitter icon facebook icon linkedin icon