Backend Development With Typescript.. Build a Web Server!

Our end product (haha!).

Typescript is great. It compiles to JavaScript with the Typescript command line tool: of which can be installed with npm. As follows:

npm i typescript -g

From there one can compile Typescript into JavaScript after declaring the build folder in the tscconfig.json file. This is as simple as crossing off the comments and writing “build” in the output folder inside the compilerOptions, called the “outDir”.

"outDir": "./build"

This can be created by the Typescript command line tool. To build a server in typescript one needs to use npm to initalize it as a node.js project.

npm init -y

Inside of the package.json file that is created edit the “main” and start script.

"main": "build/index.js",
...
"scripts": [

This is after one installs Typescript as a dependency with npm.

npm i typescript

Code to the server with express and node

let express = require('express')

Finally run the server with nodemon in the projects home directory.

nodemon

These articles pertain to Full Stack Development. Find Angular 2+ book here: https://www.lulu.com/account/projects/7dqz7r.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store