Server Side Dependency Imports

Video Lecture

Server Side Dependency Imports Server Side Dependency Imports

Description

This is predominantly a Three.js course, but we are writing the code using TypeScript, and we are also hosting the code though a NodeJS server. So we will also learn about those two things as well and how to merge these three technologies so that they work effortlessly together.

First of all, lets get the server side code running first so that it at least serves some code, and then move onto solving the problems of the client in the next video.

See Video for all npm commands and the order of execution.

src/server/server.ts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import express from "express"
import path from "path"
import http from "http"

const port: number = 3000

class App {

    private server: http.Server
    private port: number

    constructor(port: number) {
        this.port = port
        const app = express()
        app.use(express.static(path.join(__dirname, '../client')))

        this.server = new http.Server(app);
    }

    public Start() {
        this.server.listen(this.port, () => {
            console.log( `Server listening on port ${this.port}.` )
        })
    }

}

new App(port). Start()

At the end of this section, all imports for the server.ts will be properly linked, and we can then compile and view the project so far.

1
2
tsc -p ./src/server
node ./dist/server/server.js

Open a browser and visit http://127.0.0.1:3000/