GithubHelp home page GithubHelp logo

kabirbaidhya / nodejs-sample-app Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 228 KB

A ridiculously simple sample project done in NodeJS.

License: MIT License

JavaScript 84.89% CSS 3.96% HTML 9.09% Shell 2.06%
nodejs sample todoapp express rest-api angular postgresql

nodejs-sample-app's Introduction

Sample Node JS App

A ridiculously simple sample project done in NodeJS.

What do you want?

branch type of the application
hello-world A Hello world application
starter A minimalistic starter template for your next NodeJS project
rest-api A sample express application exposing REST API from a postgres database.
todoapp A full todoapp sample with angular on the frontend and the express API on the backend.

Just run git checkout <branch> and start the app.

Setup

Install dependencies

# Using npm
npm install

# Or using yarn
yarn

Configuration

Create a postgres database & import the sample todoapp database schema.

$ createdb YOUR_DATABASE

Create a .env file with your configuration.

$ cp .env.example .env

Then start the app

$ npm start

To run the database migration, run the following command

# Using npm
$ npm run migrate

# Using yarn
$ yarn migrate

To run the database seed, run the following command

# Using npm
$ npm run seed

# Using yarn
$ yarn seed

If you have node-foreman installed globally you can do

$ nf start

Test your APIs

Run npm run list:routes to list the available API routes.

$ npm run list:routes 

API Routes
----------------------------------
GET      /api/todos
POST     /api/todos
GET      /api/todos/:id
DELETE   /api/todos/:id
PUT      /api/todos/:id
----------------------------------

Now you can use http clients eg: httpie to test your APIs:

Create a todo item:

$ http --json POST http://127.0.0.1:3000/api/todos title='Build a Todo App' completed=false

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 115
Content-Type: application/json; charset=utf-8
Date: Fri, 11 Nov 2016 19:24:44 GMT
ETag: W/"73-SJsR27NngqcsXB5jUHZaXw"
X-Powered-By: Express

{
    "completed": false, 
    "description": null, 
    "id": "8", 
    "recorded_at": "2016-11-11T19:24:44.710Z", 
    "title": "Build a Todo App"
}

Now list your todos:

$ http GET http://127.0.0.1:3000/api/todos

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 117
Content-Type: application/json; charset=utf-8
Date: Fri, 11 Nov 2016 19:25:35 GMT
ETag: W/"75-ANfFIfwITLbg+u1p7PPiVA"
X-Powered-By: Express

[
    {
        "completed": false, 
        "description": null, 
        "id": "8", 
        "recorded_at": "2016-11-11T19:24:44.710Z", 
        "title": "Build a Todo App"
    }
]

Did you see that? Awesome. Now try the PUT and DELETE APIs as well.

Stay tuned

We'll be building a frontend app to make use of this todo API shortly.

nodejs-sample-app's People

Contributors

kabirbaidhya avatar vsujan avatar

Stargazers

suresh shrestha avatar Prabin Badyakar 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.