andreoneti / final-homework Goto Github PK
View Code? Open in Web Editor NEWRest API creation with Node.js
Rest API creation with Node.js
Create a lot of "readme.md" tô each rout or create a lot of Index for any routs
let example = {
up_time: Math.floor(process.uptime())
};
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(example));
var startAt = Date.now();
res.on("finish", () => {
console.log(req.method, req.originalUrl, res.statusCode, `${Date.now() - startAt} ms -`, res._contentLength.toString());
});
const notFound = (request, response, next) => {
response.status(404).json({
message: `Route to ${request.method} ${request.originalUrl} not found`
});
next && next();
}
module.exports = notFound;
HTTP/1.1 401 Unauthorized
Date: Fri, 01 Nov 2019 12:42:52 GMT
Server: Apache/2.4.25 (Debian)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *
Content-Length: 42
Connection: close
Content-Type: text/html; charset=UTF-8
"You Shall Not Pass!" - White, Gandalf the
npm install --only=production
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
createdAt: { type: Date, expires: 3600 }
function secondsToDhms(seconds) {
seconds = Number(seconds / 1000);
var d = Math.floor(seconds / (3600 * 24));
var h = Math.floor(seconds % (3600 * 24) / 3600);
var m = Math.floor(seconds % 3600 / 60);
var s = Math.floor(seconds % 60);
var ms = Math.floor((seconds * 1000) % 1000);
var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second, " : " seconds, ") : "0 seconds, ";
var msDisplay = ms > 0 ? ms + (ms == 1 ? " milisecond" : " miliseconds") : "0 miliseconds";
return dDisplay + hDisplay + mDisplay + sDisplay + msDisplay;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.