Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Proful committed Jun 8, 2011
0 parents commit 90a83c4
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nodejs + Express + Redis apps
51 changes: 51 additions & 0 deletions app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
express = require("express")
redis = require("redis")

redis_client = redis.createClient()

app = module.exports = express.createServer()
app.configure ->
app.set "views", __dirname + "/views"
app.set "view engine", "jade"
app.use express.bodyParser()
app.use express.methodOverride()
app.use app.router
app.use express.static(__dirname + "/public")

app.configure "development", ->
app.use express.errorHandler(
dumpExceptions: true
showStack: true
)

app.configure "production", ->
app.use express.errorHandler()

app.get "/songs", (req,res) ->
render_now = false
redis_client.get "global:nextSongId", (err,reply) ->
songs=[]
for uid in [1..reply]
console.log uid
redis_client.get "uid:"+uid+":songname",(err1,reply1) ->
console.log reply1
songs[uid] = reply1
console.log songs.length
if songs.length is reply
console.log "Songs: " + songs
res.render "songs", title: "Listing of all the songs",song_name: songs

app.get "/", (req, res) ->
res.render "index", title: "Excellent Song Suggest"

app.post "/", (req, res) ->
redis_client.incr "global:nextSongId", (err,reply) ->
console.log "song id: " + reply
redis_client.set "songname:"+req.body.song.name+":id",reply,redis.print
redis_client.set "uid:"+reply+":songname",req.body.song.name,redis.print

title= "Song posted sucessfully"
res.render "new", song_name: req.body.song.name,title: title

app.listen 3000
console.log "Express server listening on port %d", app.address().port
69 changes: 69 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(function() {
var app, express, redis, redis_client;
express = require("express");
redis = require("redis");
redis_client = redis.createClient();
app = module.exports = express.createServer();
app.configure(function() {
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
return app.use(express.static(__dirname + "/public"));
});
app.configure("development", function() {
return app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
app.configure("production", function() {
return app.use(express.errorHandler());
});
app.get("/songs", function(req, res) {
var render_now;
render_now = false;
return redis_client.get("global:nextSongId", function(err, reply) {
var songs, uid, _results;
songs = [];
_results = [];
for (uid = 1; 1 <= reply ? uid <= reply : uid >= reply; 1 <= reply ? uid++ : uid--) {
console.log(uid);
_results.push(redis_client.get("uid:" + uid + ":songname", function(err1, reply1) {
console.log(reply1);
songs[uid] = reply1;
console.log(songs.length);
if (songs.length === reply) {
console.log("Songs: " + songs);
return res.render("songs", {
title: "Listing of all the songs",
song_name: songs
});
}
}));
}
return _results;
});
});
app.get("/", function(req, res) {
return res.render("index", {
title: "Excellent Song Suggest"
});
});
app.post("/", function(req, res) {
var title;
redis_client.incr("global:nextSongId", function(err, reply) {
console.log("song id: " + reply);
redis_client.set("songname:" + req.body.song.name + ":id", reply, redis.print);
return redis_client.set("uid:" + reply + ":songname", req.body.song.name, redis.print);
});
title = "Song posted sucessfully";
return res.render("new", {
song_name: req.body.song.name,
title: title
});
});
app.listen(3000);
console.log("Express server listening on port %d", app.address().port);
}).call(this);
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"jade": ">= 0.0.1"
}
}
8 changes: 8 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
21 changes: 21 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

// Run $ expresso

/**
* Module dependencies.
*/

var app = require('../app')
, assert = require('assert');


module.exports = {
'GET /': function(){
assert.response(app,
{ url: '/' },
{ status: 200, headers: { 'Content-Type': 'text/html; charset=utf-8' }},
function(res){
assert.includes(res.body, '<title>Express</title>');
});
}
};
5 changes: 5 additions & 0 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h1= title
form#new_song(method='post')
label Song Name:
input(name='song[name]', type='text')
input(name='Save',value='Save',type='submit')
6 changes: 6 additions & 0 deletions views/layout.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!!!
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body!= body
2 changes: 2 additions & 0 deletions views/new.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1= "Please suggest song similar to "
h2= song_name
2 changes: 2 additions & 0 deletions views/songs.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1= "Songs stored in the Redis Database"
p= song_name

0 comments on commit 90a83c4

Please sign in to comment.