Skip to content

Get started with your first node based web api in Azure

Notifications You must be signed in to change notification settings

Scheevel/Node101

 
 

Repository files navigation

Node 101

Build Status

This repository contains code samples that will help you

  • Get started with node
  • Use Test Driven Development (TDD)
  • Use typescript
  • Use express as your app server
  • Use swagger for your API definition
  • Create a basic web API that exposes data from a mongodb database
  • Debug your web API in VS Code
  • Enable app telemetry
  • Deploy your first node based web API to Azure

Pre-requisites

Steps to try it out

Clone Node101 repo

git clone https://github.com/rajeshramabathiran/Node101.git

Install packages

npm install

Notice that all dependencies are now available in node_modules folder.

Generate js files and swagger document

The repository has a file in the root directory called gulpfile.js. This file contains the build scripts to transpile typescript to javascript. It also contians the scirpt to copy the swagger file to the target folder.

Note: Swagger is a powerful open source framework backed by a large ecosystem of tools that helps you design, build, document, and consume your RESTful APIs.

npm run build

At this point, a new folder called dist is created with all the js files and swagger.

Ensure mongodb is installed locally

Ensure that mongodb is present locally, and you are able to connect to it. Alternatively, if you have a mongodb instances running in the cloud you can use MONGODB_CONNECTIONSTRING environment variable to populate its connection string.

** Try it out **

To try out the web api, run

npm start

In the command prompt, you will notice that the web server is up and running in port 3000.

> [email protected] start /Users/rajeshramabathiran/gh/Node101
> node ./dist/index.js

Listening on port 3000

Note: If you want to use any other port, use the PORT environment variable to override it.

Node 101 web api up and running in localhost:3000

Test the web apis

To test the web apis, run

npm test
> [email protected] test /Users/rajeshramabathiran/gh/Node101
> mocha --reporter spec --compilers ts:ts-node/register 'test/**/*.ts'



  baseRoute
    ✓ should respond with HTTP 200 status

  booksRoute
    ✓ should respond with HTTP 200 status


  2 passing (73ms)

About

Get started with your first node based web api in Azure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 62.9%
  • Shell 26.6%
  • JavaScript 9.1%
  • Dockerfile 1.4%