Getting started with NodeJS

In the previous chapter, we used NodeJS, as gulp uses it. Node can be used for a server and for a command line tool. In this chapter, we will build a server and in Chapter 9, Playing Tic-Tac-Toe against an AI, we will create a command line application. If you haven't installed Node yet, you can download it from nodejs.org.

We will first create a simple server. We will use Phaethon, a package for Node that makes it easy to build a server in NodeJS. Phaethon includes type definitions, so we can use it immediately. We create a file lib/server/index.ts and add the following:

import { Server } from "phaethon"; const server = new Server(); server.listener = request => new phaethon.ServerResponse("Hello"); server.listenHttp(8800); ...

Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.