Git Product home page Git Product logo

rest-api-typescript-express's Introduction

REST API with TypeScript and Express.js

Requirements

TypeScript Project

This project contains a CRUD for SQL Server DB using Typescript, Express.js and Sequelize ORM.

Database setup

At your SQL Server instance, create a new DB and create a simple table that will contains 4 columns: id, name, description and enabled. You can use the following SQL Server Script:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Departments](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [name] [varchar](255) NOT NULL,
    [description] [varchar](255) NOT NULL,
    [enabled] [bit] NOT NULL DEFAULT 1
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Departments] ADD PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO

Configurations required in your local environment

Alternative 1

Be sure that in your local environment you have the file called .env. Within that file you should add the port where your REST API will be available and DB connection data, like this sample:

PORT=8000
DB=<YourDbName>
DB_USER=<YourDbUser>
DB_PASSWORD=<YourDbPass>
DB_HOST=<YourDbHost>
DB_PORT=1433

Alternative 2

Hard code your configurations at the file config.ts.

Run the project

In order to run locally the project you must perform the following at your command line located at the project's directory:

  • Install dependencies:
npm i
npm i typescript --save-dev
  • Run TSC in order to transpile your code to JS:
tsc
  • Run /dist/app.js with node:
node ./dist/app.js

In order to run your project with hot reload you can install nodemon:

npm i -g nodemon

Then open 2 terminals and run the following commands.

Terminal 1:

tsc --watch

Terminal 2:

nodemon ./dist/app.js

rest-api-typescript-express's People

Contributors

josema88 avatar

Stargazers

LEO avatar Michael John Rieser avatar Ryu Jongwon avatar Shehjad Ali Taus avatar

Watchers

James Cloos avatar  avatar  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.