Skip to content

Developing Node Server

Bennett Wu edited this page Sep 24, 2025 · 5 revisions

Resources

Core Technologies

Tools

Other

Setup

  1. Ensure Node.js and npm are installed on your computer.
    • Download from: https://nodejs.org/en.
      • Note: Node server was developed with Node version 20 and up in mind.
    • Node comes with npm (Node Package Manager), which we will use for managing our dependencies.
    • The commands node -v and npm -v will return the version numbers of Node and npm respectively.
      • Make sure both commands run successfully. If they don't, make sure node and npm are in your system path configuration.
  2. Ensure Git is installed on your computer. See: https://git-scm.com/
  3. Clone the repository
    git clone https://github.com/scribear/ScribeAR-NodeServer
    
  4. Move into the node-server directory
    cd ./ScribeAR-NodeServer/node-server
    
  5. Install dependencies
    npm install
    
  6. Make a copy of template.env and name it .env
  7. Edit .env to configure node server.
    • The template already contains sensible defaults. A good place to start is to leave every thing except WHISPER_SERVICE_ENDPOINT and SOURCE_TOKEN default.
    • See Configuring Node Server for details about each option.
  8. Start up your local instance. This will start the development server and automatically restart the app when you make changes.
    npm run dev
    

Building

  • To build the app for production, run
    npm run build
    
  • The build will be placed in the build folder.

Unit Testing

Node server is unit tested using Vitest. These are used to check that individual components are working as expected in isolation.

  • To run tests
    npm run test:dev
    
  • A web UI will be available for browsing test cases. In addition, you can view the test code coverage report generated by istanbul by clicking on the coverage icon in the top right of the sidebar.
  • To create new tests, create file ending with .test.ts in the same folder as the function/object you want to test.
    • The names of the test file should correspond to the name of the file containing the thing you are testing.
      • Try to avoid writing tests that involve multiple files. If you find yourself doing so, it might be a sign that the scope of your function is too big.
    • See https://vitest.dev/guide/ to learn how to use Vitest

Code Style

Node server uses eslint and prettier is analyze code to catch potential issues and ensure a consistent code style. eslint is configured to follow Google Typescript Style Guide (https://google.github.io/styleguide/tsguide.html) with some tweaks.

  • To run the linter
    npm run lint
    
  • To attempt to automatically fix linter issues
    npm run lint:fix
    

Containerization

  1. Ensure you have Docker installed. See: https://www.docker.com/
  2. Build container
    docker build -t node-server -f ./Dockerfile .
    
  3. Make a copy of template.env and name it .env
  4. Edit .env to configure container. See Configuring Docker Containers for details.
  5. Run container (listens on port 8080)
    docker run --env-file .env -p 8080:80 node-server:latest
    

Dependencies

When modifying dependencies:

  • Ensure that the changes are reflected in package.json and package-lock.json (typically done by npm automatically) and ensure they are commited to Git.
  • Separate dependencies only needed for developing the app (e.g. eslint, typescript) and dependencies needed to run the app (e.g. fastify).

File Structure

Github Actions

The Github Actions definitions for node server can be found in .github/workflows/node-server-ci.yml.

The following jobs are defined:

  • build-test-lint-node-server

    • Runs npm run build, npm run test:ci, and npm run lint to ensure that code builds, passes unit tests, and has no code style errors.
    • If any of these commands fail, the job is failed.
  • build-container-node-server

    • Builds the scribear-node-server Docker container and pushes to Dockerhub
    • Images are tagged with pull request id, branch, and Github tags.
    • Runs after build-test-lint-node-server finishes successfully

Additional Documentation

Additional documentation can be found in Documentation.

Clone this wiki locally