In my lecture on creating web applications with ExpressJS, I began by exploring Connect for NodeJS, emphasizing its role as the backbone for middleware in web applications. We then dove into ExpressJS, covering its architecture, routing, and integration with NodeJS modules, complemented by practical demonstrations. The session progressed to discussing views and layouts, where I showcased how to use template engines for dynamic content rendering. A significant focus was on 'Working with Data', where I demonstrated handling different data forms and performing CRUD operations. The lecture concluded by addressing common and advanced scenarios in ExpressJS, including cookies, sessions and authentication, ensuring the attendees gained a comprehensive understanding of ExpressJS in practical web application development.
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
}); //return success header
res.write('My server is running! ^_^'); //response
res.end(); //finish processing current request
}).listen(1234);
$ npm install connect
var connect = require('connect');
var app = connect()
.use(connect.logger('dev'))
.use(connect.static('public'))
.use(function(req, res){
res.end('hello world\n');
})
http.createServer(app).listen(3000);
var connect = require('connect'),
util = require('util');
var interceptorFunction = function(request, response, next) {
console.log(util.format('Request for %s with method %s', request.url, request.method));
next();
};
var app = connect()
// .use('/log', interceptorFunction)
.use(interceptorFunction)
.use(function onRequest(request, response) {
response.end('Hello from Connect!');
}).listen(3001);
var express = require('express');
var app = express();
app.get('/', function (request, response) {
response.send('Welcome to Express!');
});
app.get('/customer/:id', function (req, res) { res.send('Customer requested is ' + req.params['id']);
});
app.listen(3000);
require()
themapp.get('/', function (req, res) {
res.render('index');
});
var express = require('express'),
path = require('path');
var app = express();
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
});
app.get('/', function (req, res) {
res.render('empty');
});
app.listen(3000);
doctype
html(lang="en")
head
title Welcome to this emtpy page
body
res.render('index', { title: 'Customer List' });
res.render('index', { title: 'Customer List' });
var filePath = req.files.picture.path;
// ...
res.download(filePath);
res.sendfile(filePath);
app.locals.clock = { datetime: new Date().toUTCString()};