background preloader

Node JS

Facebook Twitter

Handling AJAX calls with Node.js and Express (scraping Craigslist) - Michael Herman. This tutorial is meant for someone who’s finished a basic Hello World project with Node and Express and ready to take another step. In short, I’ll show you how to search/scrape/crawl Craigslist using AJAX along with Node and Express. I assume you’re working from a Unix-based environment, already have Node and Express installed, and understand how to navigate the terminal. You can find the finished code on this repo if wish to bypass the tutorial altogether. Let’s get right to it. Here is an index of all the articles in the series that have been published to date: Project Setup Navigate to where you’d like your project to reside, then run the following command: CD into the newly created directory and install the node modules: Aside for the installed node modules/dependencies, your project structure should look like this: In short, your server-side Javascript is held in the app.js file, while the client-side file(s) will be placed in the “javascripts” directory.

Still with me? Workflow Ready? Form Validation With ExpressJS. Simple Node.js Express MVR Template. In this post we’ll walk through how to setup a simple MVR Node.js project using Express, Mongoose (MongoDB), Jade (templating) and everyauth (authentication). First off, what the fuck is MVR, think MVC but with routes instead controllers. What we’re going to be using Express for our framework Mongoose for MongoDB Jade for templating everyauth for authentication Twitter Bootstrap for styling Setup You’re going to need Node.JS, NPM, and MongoDB installed.

Open up the command line to create the project $ express examplemvr $ cd examplemvr $ rm -rf . Now open the mongo console and insert some test data Dependencies Open the examplemvr project in your favorite text editor and edit package.json to match the following package.json This tells NPM what modules we need and the versions we require. . $ npm install This will tell NPM to read the package.json and install any dependencies that are needed. Application Core Now open app.js and edit it to match the following /app.js Review Require mongoose require('. NodeJS : moduler son code. Node.js, Require and Exports. Back when I first started playing with node.js, there was one thing that always made me uncomfortable. Embarrassingly, I'm talking about module.exports. I say embarrassingly because it's such a fundamental part of node.js and it's quite simple. In fact, looking back, I have no idea what my hang up was...I just remember being fuzzy on it. Assuming I'm not the only one who's had to take a second, and third, look at it before it finally started sinking in, I thought I could do a little write up.

In Node, things are only visible to other things in the same file. By things, I mean variables, functions, classes and class members. Var x = 5; var addX = function(value) { return value + x; }; Another file cannot access the x variable or addX function. Now, before we look at how to expose things out of a module, let's look at loading a module. Var misc = require('. Of course, as long as our module doesn't expose anything, the above isn't very useful. Now we can use our loaded module: require('. Node.js, Module.Exports and Organizing Express.js Routes. A while ago I wrote a post explaining how require and module.exports work.

Today I wanted to show a practical example of how we can use that knowledge to organize routes in an express.js project. To recap the original post, module.exports is how we make something within our file publicly accessible to anything outside our file. We can export anything: a class, a hash, a function or a variable. When you require something you get whatever it exported. User = require('.

With that in mind, I happen to be building a website that'll have two distinct sections: an API and a user-facing portal. /routes /routes/api/ /routes/api/ /routes/api/ /routes/portal/ /routes/portal/ /routes/portal/ This is very Rails-esque with controller namespaces and resources. Before we can dive any further we need to understand how express loads routes. Taking a baby step, if we wanted to extract our route into its own file, we could do: class Scores extends require('.

An Absolute Beginner's Guide to Node.js. There's no shortage of Node.js tutorials out there, but most of them cover specific use cases or topics that only apply when you've already got Node up and running. I see comments every once and awhile that sound something like, "I've downloaded Node, now what? " This tutorial answers that question and explains how to get started from the very beginning. What is Node.js? A lot of the confusion for newcomers to Node is misunderstanding exactly what it is. The description on definitely doesn't help. An important thing to realize is that Node is not a webserver. Installing Node Node.js is very easy to install. I've Installed Node, now what? Once installed you'll have access to a new command called "node"

. $ node > console.log('Hello World'); Hello World undefined In the above example I typed "console.log('Hello World')" into the shell and hit enter. The other way to run Node is by providing it a JavaScript file to execute. Hello.js console.log('Hello World'); $ node hello.js Hello World. Karlbright/The-Node-Beginner-Book---Examples. Drywall - A website and user system for Node.js. The Front-End Pages Home, about, sign-up and contact us. Authentication Screens Login, forgot password and reset password. The Administration Area Manage users, accounts, admins, admin groups, statuses, categories and search.

The Account Area Mock up dashboard and account settings. Jedi Mind Development What you build with Drywall is more important than Drywall. Justin-john/node-user-management. Express/examples at master · visionmedia/express. Node-user-management/docs/ at master · justin-john/node-user-management. Express/examples/static-files/index.js at 2c174d6b3bd4cb56184bddeae15d714bb8e09c9e · visionmedia/express.

Building a Login System in Node.js and MongoDB | The choreography of color and code. This past week I finally got around to playing with Node.js and am really impressed with how simple it was to get a server and database up and running in literally minutes. Once there, I thought a good first project to explore the platform would be to try building a simple login system analogous to what I feel like I’ve built a million times in mysql & php. So after thinking about it a bit, I knew these were the basic features I wanted to implement : Login Panel Just a simple login panel with the ability to reset a lost password and of course the ability to create an account for first time users.An option to “remember me” that saves the user’s data in a local cookie allowing them to bypass the login screen whenever they revisit the site.

New Account Screen A simple form that allows a new user to set their username & password,as well as some personal data such as their real name, email and location. Account Update Screen Password Retrieval If you’d like to jump ahead : Application Structure. Building a Login System in Node.js and MongoDB | The choreography of color and code. An example NodeJS / Mongoose / Express application based on their respective tutorials. SOAP vs. REST : choisir la bonne architecture web services. De plus en plus d’entreprises ont besoin de rendre leurs applications accessibles sur le web. Les motivations sont multiples : élargir l’audience des utilisateurs, vendre des services en ligne, faire communiquer des applications existantes ou supporter une interface de type AJAX. Dans ces conditions, quelle architecture choisir ou concevoir ?

Quel format utiliser pour échanger des données sur le web ? Et devrait-on utiliser un protocole applicatif existant ou développer un protocole adapté à nos besoins ? Table des matières Introduction Nous parlons ici de mettre en place un protocole applicatif sur le web pour échanger de l’information avec un grand nombre de clients. Le développement de protocoles applicatifs Rendre ses applications accessibles sur le web consiste à définir un protocole applicatif et un format de données.

Nous avons vu que les motivations des entreprises pour déployer des web services aujourd’hui étaient nombreuses. Choisir SOAP ? Alors quel avenir pour SOAP ? Tableau 1. Need 11 reasons to love jade template engine? Look no further! | NodeJS rocks. Problem Node.js is based on event-driven IO. Accessing file system, data base, network, ... happens in most cases asynchronously. If calls depend on each other, you have to synchronize, this often ends up in deeply nested spaghetti code.

If you have a couple of async function calls where one depends on the result of the other, you may end up with something like this: And if you add exception handling and need additional steps, code will become unmaintainable. If you use SEQ, above code would look like this: What is the difference between __dirname and ./ in node.js. Jade Template Syntax Documentation by Example. Webapplications with node.js – Jade | iPROFS Technology Blog.

In my previous post I described how you can install node.js and how to use express.js to create a webapplication for the node.js server. Now it is time to look into the templating engine – Jade – that express uses for outputting html to the browser. As I did not have any knowledge yet of jade, it was time for me to do a quick study of jade. As a lot of github projects, the initial documentation is rather sparse, since it only showed an example of the jade template language will be translated into html. But luckily clicking on the github fork ribbon showed some more documentation on github. Starting So I copied the twitter bootstrap files that I was using in the play-petclinic example and changed the default layout.jade file: link(rel='stylesheet', href='/stylesheets/uniform.default.css') link(rel='stylesheet', href='/stylesheets/twitter.css') started the node engine.

Restarted node.js, and looking at the code and it looked readable. Layouting using a default layout extends layout !!! Result <! Webapplications with node.js – Jade | iPROFS Technology Blog. Jade – Node Template Engine | Harry Torry. Coming from a strong php background, where the back-end is integrated into the front end, I immediately opened my arms towards Jade. Don’t get me wrong, there are templating engines such as Smarty and Mustache (PHP & JS). It has made creating views for data to be a lot easier than I remembered in stock php. I don’t know why I never went further than using Mustache in my career. It is currently ranked 12th (as of 22/10/2013) in the Most Depended-upon Packages on the official NPM website. Installation $ npm install jade Since we’re dealing with Node and NPM, installation is practically effortless. How to use it Jade is (to me at least) a minimalist way of creating markup and it is whitespace sensitive.

This will generate something that looks a little bit like this (Note – I indented the generated code): Text and Comments Text inside paragraph tag Multi Line Another way for large bodies of text in case we have a lot to say for a single paragraph. Nesting Variables and Escaping Official Documentation. Jade tutorial. Créer un site simple avec Node.js, Express et Jade - Code4fun - Dev Blog. Express est un framework permettant de créer des applications web avec nodejs. Dans cette article nous allons développer un mini site basé sur le framework Express et son moteur de template par defaut : Jade (Voir la demo). Certains sites à fort trafic utilisent déjà Express en production comme : Pour la suite de l’article vous devez disposer du gestionnaire de paquet NPM ainsi que d’un environnement nodejs.

Installation/Configuration Commencez par installer express via le gestionnaire de paquet npm : Puis créez un projet express en utilisant la commande : Et pour finir installez les dépendances : La commande npm install se sert du package.json pour connaitre les modules à installer. Vous pouvez maintenant lancer le serveur (node app.js), le site est accessible en local sur le port 3000: Comment ça marche ? Express a généré un projet contenant : Regardons de plus près app.js : Par défault express déporte les routes dans routes/index.js. Permet de lier la requête GET / à la fonction : CRUD Introduction — MongoDB Manual 2.4.8. MongoDB stores data in the form of documents, which are JSON-like field and value pairs. Documents are analogous to structures in programming languages that associate keys with values, where keys may hold other pairs of keys and values (e.g. dictionaries, hashes, maps, and associative arrays).

Formally, MongoDB documents are BSON documents, which is a binary representation of JSON with additional type information. For more information, see Documents. A MongoDB document. MongoDB stores all documents in collections. A collection is a group of related documents that have a set of shared common indexes. Collections are analogous to a table in relational databases. A collection of MongoDB documents. Database Operations Query In MongoDB a query targets a specific collection of documents. In the following diagram, the query process specifies a query criteria and a sort modifier: The stages of a MongoDB query with a query criteria and a sort modifier. See Read Operations Overview for more information. Password-hash. Node-password-hash password-hash is a node.js library to simplify use of hashed passwords. Storing passwords in plain-text is bad. This library makes the storing of passwords (and subsequent validation of) hashed passwords a bit easier. password-hash provides functions for generating a hashed passwords and verifying a plain-text password against a hashed password.

For a bit of added strength, a random salt is generated when the password is hashed. The hashed password contains both the cryptographic algorithm that was used as well the salt, so all that is needed to verify a plain-text password is the hashed password itself. Installation npm install password-hash Usage generate(password, [options]) Generates a hash of the required password argument.

Errors are thrown if: password is not a stringoptions.algorithm is specified but not a valid cryptographic algorithmoptions.saltLength is specified but not a positive integer The hashed password will be in the format algorithm$salt$hash. Example: Installation et bases de MongoDB - Syrinxoon Tuts. MongoDB est l'une des bases de données composant le mouvement NoSQL au même titre que qu'Apache CouchDB pour ne citer qu'elle.

L'intérêt de ce genre de bases de données se ressent dans la manipulation de très grosses bases de données où le temps de réponse compte plus que l'intégrité des données. En effet, les bases NoSQL sont des SGBD et laissent ainsi tomber le R de relationnel au profit d'une plus grande simplicité, performance et montée en charge. Pour en apprendre plus au sujet des bases de données NoSQL et de leurs différences, je ne saurais que trop vous conseiller le livre Seven Databases in Seven Weeks: A Guide to Modern Databases and the NoSQL Movement (lien sponsorisé) à paraître mi-Avril. Le livre est anglais mais si ça ne vous dérange pas alors foncez, vous ne serez pas déçu.

Ce tutoriel à pour but de vous faire découvrir MongoDB via la ligne de commande et via deux langages de programmation que sont PHP et Ruby. Allons y ! Installation sur Linux Si vous êtes en 32 bits : NodeJS by Example. Introduction to Node.js with Ryan Dahl. Jade - Template Engine. Passport - Simple, unobtrusive authentication for Node.js. 10 Node.js Modules You May Not Know About. Npm cheatsheet - A Sample App with Node.js, Express and MongoDB – Part 1 | Dev Notes. The Node Beginner Book » A comprehensive Node.js tutorial.

Introduction to npm. Mot-clé - package.json. The cross-browser WebSocket for realtime apps.