background preloader

Express

Facebook Twitter

Creating RESTful APIs With NodeJS and MongoDB Tutorial (Part II) - Adrian Mejia’s Blog. Welcome to this RESTful API using Node.js (Express.js) and MongoDB (mongoose) tutorial. You can follow alone to make a stand alone API endpoint, or you could also check out our AngularJS or BackboneJS tutorials to build a javascript-client that connects with the endpoint we are going to built. What RESTful API really means? REST stands for Representational State Transfer. It is an architecture that allows client-server communication through a uniform interface. They are also stateless, cachable and has property called idempotence, which means that the side effect of multiple identical requests have the same effect as the same single request.

HTTP RESTful API’s are compose of: HTTP methods, e.g. Here’s is a summary what we want to implement: NOTES: * Format will be JSON. * Bulk updates and bulk destroys are not safe, so we will not be implementing those. * POST, GET, PUT, DELETE == CREATE, READ, UPDATE, DELETE == CRUD. Setup The two main components of the MEAN stack are… NodeJS and MongoDB.

Handle GET and POST Request in Express 4 | Code for geek. As per the documentation GET request are meant to fetch data from specified resource and POST are meant to submit data to a specified resource. Express allows you to handle GET and POST request using the instance of express. Due to the depreciation of connect middle-ware handling POST request however seems confusing to many people. GET request: Handling GET request in Express seems so easy. You have to create instance of express and call get method. Here is small snippet to demonstrate that. var express = require("express");var app = express(); app.get('handle',function(request,response){//code to perform particular action. GET request can be cached and remains in browser history. POST Request: Express version 4 and above requires extra middle-ware layer to handle POST request.

You can install bodyParser by two way. Sudo npm install --save body-parser You have to import this package in your project and tell Express to use this as middle-ware. Demo App : Login System package.json server.js. Hosting multiple Express (node.js) apps on port 80 - Nerdpress.org. Nodejitsu/node-http-proxy. Node.js - how to put nodejs and apache in the same port 80. Conditional URL rewrite forwarding. Combining Node.js & Apache. Chungsub Kim : Run Node.js as a Service on Ubuntu. Chungsub Kim : Run Node.js as a Service on Ubuntu. Node.JS et Express. Je me rends compte que dans ce blog je vous parle de Node.JS et d’Express, sans vous avoir jamais présenté ces technologies.

Allez, revenons vite fait aux bases Installation Pour l’installation, je vous renvoie au site officiel, ou à un article en français par Atinux, mais globalement l’installation se résume à ces 3 lignes: Présentation de Node.JS Node.JS est un projet open-source se basant sur le moteur « V8″ de Chrome (il existe un fork « SpiderNode » par Mozilla, basé sur leur moteur SpiderMonkey). Il s’agit donc finalement d’un simple interpréteur Javascript, exécutable, et enrichissant le langage avec sa propre API (accès au système de fichier, à la couche réseau, etc.). Ça permet, en résumé, d’exécuter des fichiers « .js » comme des scripts PHP, Python, Ruby, etc… Tout ça tombe bien, les gens du Web a priori savent déjà un peu utiliser Javascript Le module « async.js » permet de simplifier ce type de code.

Les modules Les dépôts de modules: NPM Exemple d’un package.json minimal: Express Node.js Web Framework.