Git Product home page Git Product logo

simple-math-api-exercise's Introduction

simple-math-api-exercise

Node.js + Express + TypeScript math api

Here's a skeleton for us to clone in the 6th fCC meetup in Ikea

Development

This project requires Node.JS installed, a JavaScript runtime that runs code inside a v8 engine without a browser. See more on how to install it at nodejs.org.

Clone it and start from there.

git clone https://github.com/Unisergius/simple-math-api-exercise.git
# or over ssh
git clone [email protected]:Unisergius/simple-math-api-exercise.git

To install this project's dependencies, you have to run the following command from a terminal inside the project's directory.

# change into the git's directory if needed
cd simple-math-api-exercise
# install dependencies
npm install

This installs the node dependencies into the node_modules directory, what some may know them as vendors folder.

The dependencies for this project are bellow with a few links on how they work and their documentaion:

Node.js executes JavaScript code, but as you can see this project uses TypeScript as its scripting language. What this means is that our code is type checked using TypeScript but needs to be compiled for Node.js to be able to read our code.

To compile the code to JavaScript you can run the build command using npm. This is actually running the TypeScript compiler using tsc, the reason to not directly run the tsc command is that you may not have TypeScript installed globally in your system. This is actually good since it forces your machine to run the TypeScript compiler for the verison defined in the dependencies.

npm run build

Our server is written is Express, a Node.js library that facilitates the handling of http requests to a server in JavaScript. Our handlers are all inside of the index.ts file. Go take a look.

To start the Express application, run the following command:

npm start
# or if you need to rebuild and run again
npm run build && npm start

To change the port the web server runs on, you can create a copy of the .env.example file and rename it to .env, then write the port into the variable.

PORT=8080

Antoher way to set the port without the need to create a .env file is to set the enviroment variable like bellow

export PORT=8080
npm start
# or just
PORT=8080 npm start

Testing

Now that we have the basics of how to run the application, we need to test make the application bullet-proof. This project includes Jest as a dependency and has some simple tests inside the test directory to make sure our math library works like intended.

To just run the tests, run the following command:

npm run test

Jest includes a tool to check if you've covered all of your possible use cases within your code. This type of checking is called Code Coverage, where your code is analysed by a software that checks every possible coditional path inside of your code, then checks which paths your tests actually run through and when it finishes it outputs a percentage value of how much of your code is actually covered by test cases. To read more about code coverage, you can read the wikipedia article.

To run the coverage check, run the following command:

npm run test:coverage

From Scratch

This project is based on a logrocket article: Setup node express typescript server, to start from scratch:

# Initialize a npm project
npm init -y
# Install deployment dependencies
npm install express dotenv
# Install development dependencies
npm i -D typescript @types/express @types/node

simple-math-api-exercise's People

Contributors

unisergius avatar onelikeandidie avatar jonasschmedtmann avatar pdelrc avatar karlthomas3 avatar pedrocavalheiro avatar zinixyt avatar monkzzz avatar akeren avatar

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.