"They ask me how I do it
I just bite off more then I can chew
And then I chew it"
(groupings of one or more custom modules)
sorry, don't remember the source
const server = http.createServer((req, res) => {
const page = url.parse(req.url).pathname;
const params = querystring.parse(url.parse(req.url).query);
console.log(page);
if (page == '/') {
fs.readFile('index.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
else if (page == '/otherpage') {
fs.readFile('otherpage.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
else if (page == '/otherotherpage') {
fs.readFile('otherotherpage.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
else if (page == '/api') {
if('student' in params){
if(params['student']== 'leon'){
res.writeHead(200, {'Content-Type': 'application/json'});
const objToJson = {
name: "leon",
status: "Boss Man",
currentOccupation: "Baller"
}
res.end(JSON.stringify(objToJson));
}//student = leon
else if(params['student'] != 'leon'){
res.writeHead(200, {'Content-Type': 'application/json'});
const objToJson = {
name: "unknown",
status: "unknown",
currentOccupation: "unknown"
}
res.end(JSON.stringify(objToJson));
}//student != leon
}//student if
}//else if
else if (page == '/css/style.css'){
fs.readFile('css/style.css', function(err, data) {
res.write(data);
res.end();
});
}else if (page == '/js/main.js'){
fs.readFile('js/main.js', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write(data);
res.end();
});
}else{
figlet('404!!', function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
res.write(data);
res.end();
});
}
});
server.listen(8000);
Fast, unopinionated, minimalist web framework for Node.js
With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.
Create (post) - Make something
Read (get) - Get Something
Update (put) - Change something
Delete (delete) - Remove something
Client (Laptop)
Browser
URL
Server
Disk
API Code
Files
Mongo
Database
Collection
Collection
document
document
document
document
app.get('/')
app.post('/form')
app.put('/info')
app.delete('/info')
/views
/public
index.ejs
main.js
style.css
Fonts
Images
Client (Laptop)
Browser
URL
Server
Disk
API Code
Files
Mongo
Database
Collection
Collection
document
document
document
document
app.get('/')
app.post('/form')
app.put('/info')
app.delete('/info')
/views
/public
index.ejs
main.js
style.css
Fonts
Images
Machine Learning "System" that takes inputs, processes them, and produces outputs based on patterns it has learned from data
Trained on billions of words and now can predict the most likely next set of words based on what it has learned
The information or environment that makes everything make sense
Past Conversation
Who, what, where
What you are doing
With context: COLD
Without context: Huh?
Set of rules and/or procedures for how something should be done
Get
Post
Put
Delete
Tools
Resources
Think Get
Think Post