Skip to content

Instantly share code, notes, and snippets.

@arisetyo
Last active August 29, 2015 13:56
Show Gist options
  • Save arisetyo/9222916 to your computer and use it in GitHub Desktop.
Save arisetyo/9222916 to your computer and use it in GitHub Desktop.
Node and Express 101
var express = require('express');
var app = express();
//configuration
app.configure(function () {
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(app.router);
});
//url request example 1
app.get('/test', function(req, response) {
response.send("test get request");
});
//url request example 2
app.get('/object', function(req, response) {
var obj = {nama:"Node", fungsi:"network server", bahasa:"JavaScript"};
response.send(obj);
});
//url request example 3
app.get('/content.html', function(req, response) {
var con = "<html><body><h1>Hello from Node</h1></body></html>";
response.send(con);
});
//run on port 8070
app.listen(8070);
console.log('server is listening on port 8070');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment