Code Monkey home page Code Monkey logo

typescript-express-server's Introduction

Typescript-Express-Server

Example Express Server using Typescript which can be deployed via Heroku

##Difference from deploying normal nodejs app in Heroku

  • Install typescript, typings via npm
  • Init typings

typings init

This will create a typings.json that contains dependancies.

  • Install required typings (node, express in this case)

Microsoft guide : https://code.visualstudio.com/docs/runtimes/nodejs#_typings

typings install node --ambient --save

OR use like this: typings install dt~node --save --global

typings install express serve-static express-serve-static-core --ambient --save

typings install mime --ambient --save

Dependencies will be added to typings.json and thus you can gitignore typings folder. Later you can use this command to install dependencies

typings install

  • Init tsc

tsc --init

This will create a tsconfig.json that contains compilerOptions required for typescript compiler. Make required changes.

  • Add a reference to the main typings file (something.d.ts) in index.ts
  • Create Procfile which asks to install all typings dependencies, run tsc command (to create corresponding .js file wherever specified) and start node
  • Add all js files (*.js), typings folder in gitignore (and node_modules as usual). tsc command in Procfile will generate those for us.

###Note App can also be deployed to Heroku without initializing typings, tsc (where both tsconfig.json, typings.json wont be there). Instead you have to push typings folder completely to Heroku GIT. And make necessary changes in Procfile, so that there is no need to install typings seperately and add tsc compilerOptions directly in Procfile itself

./node_modules/.bin/tsc --module commonjs --outDir build/ --noImplicitAny --sourceMap --target ES5 index.ts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.