Posts

Showing posts with the label express

Making a scraper in Node.js...

Let's make a multi link crawler for a multi page query in a web page listing jobs opportunities. First let's make a module of it, in a separate file from our server in node whatever it is and we gonna call it with var worker = require( 'worker.js' ); It will be called with this sentence from our express router or whatever you are using. First we gonna need two libraries  var request = require( "request" ); var cheerio = require( "cheerio" ); One for making requests more easy(request) and another for making jQuery available on the server side(cheerio). Now we need the list of pages of the main web site, this one makes a default paged list with the jobs listed that day in in one link, and paginates on base of that link so... var url = "http://www.bumeran.com.ar/empleos-publicacion-hoy.html" ; Now for exporting this function to the node server we gona make a "start" function

Mini Tutorial Node.js, Express, and Jade.

Image
I was having some problems deploying some jade web pages over Node.js with Jade template engine. So I'm leaving a small tutorial for not forgetting what i have done so far... Let's see first install everything we need: >npm install express >npm install jade Now we have the pieces lest make the directory structure for this project, just add the directories "views" and "public" we will save the static things in public, like JavaScript and CSS files and jade views in views. Pretty obvious right... Now lets write some server code... var app = express(); app.configure(function(){ app.set('port', process.env.PORT || 3000); //set the port app.set('views', __dirname + '/views'); //set views dir app.set('view engine', 'jade'); // set the template engine a pp.use(express.favicon()); //set the favicon app.use(express.static(path.join(__dirname, 'public

Let's send some mails via Node.js

Image
In my Android app I'm having a unique comments section from the users to contact me, they send comments and messages to my mail via this layout... Now lets see i want to send a mail, with this three fields, to myself, via my app... I know! An get request to a server, sending this three fields in a mail to myself! Let's do this... first of all... lets fins a library that sends mails bingo!  Nodemailer it s very appropriate for this task... https://github.com/andris9/Nodemailer https://npmjs.org/package/nodemailer Lets's install it.. I use Cloud9 for developing in Node.js the pros are enough and the ide just IDE just works it coud debug in real time, and it got an console with some practice you can make a server and deploying it in no time, now lets see install node mailer. Node has npm (node package manager) it resolves the dependencies via the Package.json or installing the stuf directly into the app via the npm install <name_of_the_library>, we go