├── .gitignore ├── README.md ├── css ├── normalize.css └── style.css ├── index.html ├── js ├── banki.js └── main.js ├── package-lock.json ├── package.json └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Full Stack Web Development Interview Questions 2 | This is a full stack web dev interview flashcard app containing 150+ questions covering a large range of behavioral and technical questions. 3 | 4 | **Link to project:** https://full-stack-interview-prep.up.railway.app/ 5 | 6 | - [Full Stack Web Development Interview Questions](#full-stack-web-development-interview-questions) 7 | - [How It's Made:](#how-its-made) 8 | - [Lessons Learned:](#lessons-learned) 9 | - [Installation](#installation) 10 | - [Dependencies](#dependencies) 11 | - [Usage](#usage) 12 | 13 |
14 |
15 |
data−
attributes good for?", type: "HTML" },
92 | {
93 | question: "Consider HTML5 as an open web platform. What are the building blocks of HTML5?",
94 | type: "HTML",
95 | },
96 | {
97 | question: "Describe the difference between a cookie
, sessionStorage
and localStorage
.",
98 | type: "HTML",
99 | },
100 | {
101 | question:
102 | "Describe the difference between <script>
, <script async>
and <script defer>
.",
103 | type: "HTML",
104 | },
105 | {
106 | question:
107 | "Why is it generally a good idea to position CSS <link>s
between <head></head>
and JS <script>s
just before </body>
? Do you know any exceptions?",
108 | type: "HTML",
109 | },
110 | { question: "What is progressive rendering?", type: "HTML" },
111 | {
112 | question:
113 | "Why would you use a srcset
attribute in an image tag? Explain the process the browser uses when evaluating the content of this attribute.",
114 | type: "HTML",
115 | },
116 | {
117 | question: "Have you used different HTML templating languages before?",
118 | type: "HTML",
119 | },
120 | {
121 | question: "What is CSS selector specificity and how does it work?",
122 | type: "CSS",
123 | },
124 | {
125 | question: "What's the difference between 'resetting' and 'normalizing' CSS? Which would you choose, and why?",
126 | type: "CSS",
127 | },
128 | {
129 | question: "Describe floats and how they work.",
130 | type: "CSS",
131 | },
132 | {
133 | question: "Describe z−index
and how stacking context is formed.",
134 | type: "CSS",
135 | },
136 | {
137 | question: "Describe BFC (Block Formatting Context) and how it works.",
138 | type: "CSS",
139 | },
140 | {
141 | question: "What are the various clearing techniques and which is appropriate for what context?",
142 | type: "CSS",
143 | },
144 | {
145 | question: "Explain CSS sprites, and how you would implement them on a page or site.",
146 | type: "CSS",
147 | },
148 | {
149 | question: "How would you approach fixing browser−specific styling issues?",
150 | type: "CSS",
151 | },
152 | {
153 | question: "How do you serve your pages for feature−constrained browsers? What techniques/processes do you use?",
154 | type: "CSS",
155 | },
156 | {
157 | question: "What are the different ways to visually hide content (and make it available only for screen readers)?",
158 | type: "CSS",
159 | },
160 | {
161 | question: "Have you ever used a grid system, and if so, what do you prefer?",
162 | type: "CSS",
163 | },
164 | {
165 | question: "Have you used or implemented media queries or mobile specific layouts/CSS?",
166 | type: "CSS",
167 | },
168 | {
169 | question: "Are you familiar with styling SVG?",
170 | type: "CSS",
171 | },
172 | {
173 | question: "Can you give an example of an @media
property other than screen?",
174 | type: "CSS",
175 | },
176 | {
177 | question: "What are some of the 'gotchas' for writing efficient CSS?",
178 | type: "CSS",
179 | },
180 | {
181 | question: "What are the advantages/disadvantages of using CSS preprocessors?",
182 | type: "CSS",
183 | },
184 | {
185 | question: "Describe what you like and dislike about the CSS preprocessors you have used.",
186 | type: "CSS",
187 | },
188 | {
189 | question: "How would you implement a web design comp that uses non−standard fonts?",
190 | type: "CSS",
191 | },
192 | {
193 | question: "Explain how a browser determines what elements match a CSS selector.",
194 | type: "CSS",
195 | },
196 | {
197 | question: "Describe pseudo−elements and discuss what they are used for.",
198 | type: "CSS",
199 | },
200 | {
201 | question:
202 | "Explain your understanding of the box model and how you would tell the browser in CSS to render your layout in different box models.",
203 | type: "CSS",
204 | },
205 | {
206 | question: "What does * { box−sizing: border−box; }
do? What are its advantages?",
207 | type: "CSS",
208 | },
209 | {
210 | question: "What is the CSS display property and can you give a few examples of its use?",
211 | type: "CSS",
212 | },
213 | {
214 | question: "What's the difference between inline and inline−block
?",
215 | type: "CSS",
216 | },
217 | {
218 | question: "What's the difference between a relative, fixed, absolute and statically positioned element?",
219 | type: "CSS",
220 | },
221 | {
222 | question: "What existing CSS frameworks have you used locally, or in production? How would you change/improve them?",
223 | type: "CSS",
224 | },
225 | {
226 | question: "Have you played around with the new CSS flexbox or grid
specs?",
227 | type: "CSS",
228 | },
229 | {
230 | question: "Can you explain the difference between coding a web site to be responsive versus using a mobile−first strategy?",
231 | type: "CSS",
232 | },
233 | {
234 | question: "How is responsive design different from adaptive design?",
235 | type: "CSS",
236 | },
237 | {
238 | question: "Have you ever worked with retina graphics? If so, when and what techniques did you use?",
239 | type: "CSS",
240 | },
241 | {
242 | question: "Is there any reason you'd want to use translate()
instead of absolute positioning, or vice−versa? And why?",
243 | type: "CSS",
244 | },
245 | {
246 | question: "Explain event delegation.",
247 | type: "JavaScript",
248 | },
249 | {
250 | question: "What's the difference between .call
and .apply
?",
251 | type: "JavaScript",
252 | },
253 | {
254 | question: "Explain how this
works in JavaScript.",
255 | type: "JavaScript",
256 | },
257 | {
258 | question: "Explain how prototypal inheritance works.",
259 | type: "JavaScript",
260 | },
261 | {
262 | question: "What do you think of AMD vs CommonJS?",
263 | type: "JavaScript",
264 | },
265 | {
266 | question:
267 | "Explain why the following doesn't work as an IIFE: function foo(){ }();
. What needs to be changed to properly make it an IIFE?",
268 | type: "JavaScript",
269 | },
270 | {
271 | question:
272 | "What's the difference between a variable that is: null
, undefined
or undeclared? How would you go about checking for any of these states?",
273 | type: "JavaScript",
274 | },
275 | {
276 | question: "What is a closure, and how/why would you use one?",
277 | type: "JavaScript",
278 | },
279 | {
280 | question:
281 | "Can you describe the main difference between a .forEach
loop and a .map()
loop and why you would pick one versus the other?",
282 | type: "JavaScript",
283 | },
284 | {
285 | question: "What's a typical use case for anonymous functions?",
286 | type: "JavaScript",
287 | },
288 | {
289 | question: "How do you organize your code? (module pattern, classical inheritance?)",
290 | type: "JavaScript",
291 | },
292 | {
293 | question: "What's the difference between host objects and native objects?",
294 | type: "JavaScript",
295 | },
296 | {
297 | question:
298 | "Difference between: function Person(){}
, var person = Person()
, and var person = new Person()
?",
299 | type: "JavaScript",
300 | },
301 | {
302 | question: "Explain Function.prototype.bind
.",
303 | type: "JavaScript",
304 | },
305 | {
306 | question: "When would you use document.write()
?",
307 | type: "JavaScript",
308 | },
309 | {
310 | question: "What's the difference between feature detection, feature inference, and using the UA string?",
311 | type: "JavaScript",
312 | },
313 | {
314 | question: "Explain Ajax in as much detail as possible.",
315 | type: "JavaScript",
316 | },
317 | {
318 | question: "What are the advantages and disadvantages of using Ajax?",
319 | type: "JavaScript",
320 | },
321 | {
322 | question: "Explain how JSONP works (and how it's not really Ajax).",
323 | type: "JavaScript",
324 | },
325 | {
326 | question: "Have you ever used JavaScript templating? If so, what libraries have you used?",
327 | type: "JavaScript",
328 | },
329 | {
330 | question: "Explain 'hoisting'.",
331 | type: "JavaScript",
332 | },
333 | {
334 | question: "Describe event bubbling.",
335 | type: "JavaScript",
336 | },
337 | {
338 | question: "What's the difference between an attribute
and a property
?",
339 | type: "JavaScript",
340 | },
341 | {
342 | question: "Why is extending built−in JavaScript objects not a good idea?",
343 | type: "JavaScript",
344 | },
345 | {
346 | question: "Difference between document load
event and document DOMContentLoaded
event?",
347 | type: "JavaScript",
348 | },
349 | {
350 | question: "What is the difference between ==
and ===
?",
351 | type: "JavaScript",
352 | },
353 | {
354 | question: "Explain the same−origin policy with regards to JavaScript.",
355 | type: "JavaScript",
356 | },
357 | {
358 | question: "Make this work: duplicate([1,2,3,4,5]); // [1,2,3,4,5,1,2,3,4,5]
",
359 | type: "JavaScript",
360 | },
361 | {
362 | question: 'Why is it called a Ternary expression, what does the word "Ternary" indicate?',
363 | type: "JavaScript",
364 | },
365 | {
366 | question: "What is use strict;
? what are the advantages and disadvantages to using it?",
367 | type: "JavaScript",
368 | },
369 | {
370 | question:
371 | 'Create a for loop that iterates up to 100
while outputting "fizz" at multiples of 3
, "buzz" at multiples of 5
and "fizzbuzz" at multiples of 3
and 5
',
372 | type: "JavaScript",
373 | },
374 | {
375 | question: "Why is it, in general, a good idea to leave the global scope of a website as−is and never touch it?",
376 | type: "JavaScript",
377 | },
378 | {
379 | question:
380 | "Why would you use something like the load
event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?",
381 | type: "JavaScript",
382 | },
383 | {
384 | question: "Explain what a single page app is and how to make one SEO−friendly.",
385 | type: "JavaScript",
386 | },
387 | {
388 | question: "What is the extent of your experience with Promises and/or their polyfills?",
389 | type: "JavaScript",
390 | },
391 | {
392 | question: "What are the pros and cons of using Promises instead of callbacks?",
393 | type: "JavaScript",
394 | },
395 | {
396 | question: "What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?",
397 | type: "JavaScript",
398 | },
399 | {
400 | question: "What tools and techniques do you use debugging JavaScript code?",
401 | type: "JavaScript",
402 | },
403 | {
404 | question: "What language constructions do you use for iterating over object properties and array items?",
405 | type: "JavaScript",
406 | },
407 | {
408 | question: "Explain the difference between mutable and immutable objects.",
409 | type: "JavaScript",
410 | },
411 | {
412 | question: "Explain the difference between synchronous and asynchronous functions.",
413 | type: "JavaScript",
414 | },
415 | {
416 | question: "What is the event loop? What is the difference between call stack and task queue?",
417 | type: "JavaScript",
418 | },
419 | {
420 | question: "Explain the differences on the usage of foo between function foo() {}
and var foo = function() {}
",
421 | type: "JavaScript",
422 | },
423 | {
424 | question: "What are the differences between variables created using let
, var
or const?
",
425 | type: "JavaScript",
426 | },
427 | {
428 | question: "What are the differences between ES6 class and ES5 function constructors?",
429 | type: "JavaScript",
430 | },
431 | {
432 | question: "Can you offer a use case for the new arrow => function syntax? How does this new syntax differ from other functions?",
433 | type: "JavaScript",
434 | },
435 | {
436 | question: "What is Node.js? Where can you use it?",
437 | type: "Node.js",
438 | },
439 | {
440 | question: "Why use Node.js?",
441 | type: "Node.js",
442 | },
443 | {
444 | question: "What are the features of Node.js?",
445 | type: "Node.js",
446 | },
447 | {
448 | question: "How do you update npm
to a new version in Node.js?",
449 | type: "Node.js",
450 | },
451 | {
452 | question: "Why is Node.js Single−threaded?",
453 | type: "Node.js",
454 | },
455 | {
456 | question: "Explain callback in Node.js.",
457 | type: "Node.js",
458 | },
459 | {
460 | question: "What is callback hell in Node.js?",
461 | type: "Node.js",
462 | },
463 | {
464 | question: "How do you prevent/fix callback hell?",
465 | type: "Node.js",
466 | },
467 | {
468 | question: "Explain the role of REPL in Node.js.",
469 | type: "Node.js",
470 | },
471 | {
472 | question: "Name the types of API functions in Node.js.",
473 | type: "Node.js",
474 | },
475 | {
476 | question: "What are the functionalities of npm
in Node.js?",
477 | type: "Node.js",
478 | },
479 | {
480 | question: "What is the difference between Node.js and Ajax?",
481 | type: "Node.js",
482 | },
483 | {
484 | question: "What are “streams” in Node.js? Explain the different types of streams present in Node.js.",
485 | type: "Node.js",
486 | },
487 | {
488 | question: "Explain chaining in Node.js.",
489 | type: "Node.js",
490 | },
491 | {
492 | question: "What are Globals in Node.js?",
493 | type: "Node.js",
494 | },
495 | {
496 | question: "What is Event−driven programming?",
497 | type: "Node.js",
498 | },
499 | {
500 | question: "What is the Event loop in Node.js? And How does it work?",
501 | type: "Node.js",
502 | },
503 | {
504 | question: "What is the purpose of module.exports
in Node.js?",
505 | type: "Node.js",
506 | },
507 | {
508 | question: "What is the difference between Asynchronous and Non−blocking?",
509 | type: "Node.js",
510 | },
511 | {
512 | question: "What is Tracing in Node.js?",
513 | type: "Node.js",
514 | },
515 | {
516 | question: "How will you debug an application in Node.js?",
517 | type: "Node.js",
518 | },
519 | {
520 | question: "Difference between setImmediate()
vs setTimeout()
?",
521 | type: "Node.js",
522 | },
523 | {
524 | question: "What is process.nextTick()
.",
525 | type: "Node.js",
526 | },
527 | {
528 | question: "What is package.json
? What is it used for?",
529 | type: "Node.js",
530 | },
531 | {
532 | question: "What is libuv
?",
533 | type: "Node.js",
534 | },
535 | {
536 | question: "What are some of the most popular modules of Node.js?",
537 | type: "Node.js",
538 | },
539 | {
540 | question: "What is EventEmitter
in Node.js?",
541 | type: "Node.js",
542 | },
543 | {
544 | question: "What advantage is there for using the arrow syntax for a method in a constructor?",
545 | type: "JavaScript",
546 | },
547 | {
548 | question: "What is the definition of a higher−order function?",
549 | type: "JavaScript",
550 | },
551 | {
552 | question: "Can you give an example for destructuring an object or an array?",
553 | type: "JavaScript",
554 | },
555 | {
556 | question: "ES6 Template Literals offer a lot of flexibility in generating strings, can you give an example?",
557 | type: "JavaScript",
558 | },
559 | {
560 | question: "Can you give an example of a curry function and why this syntax offers an advantage?",
561 | type: "JavaScript",
562 | },
563 | {
564 | question: "What are the benefits of using spread syntax and how is it different from rest syntax?",
565 | type: "JavaScript",
566 | },
567 | {
568 | question: "How can you share code between files?",
569 | type: "JavaScript",
570 | },
571 | {
572 | question: "Why might you want to create static class members?",
573 | type: "JavaScript",
574 | },
575 | {
576 | question: "Can you name two programming paradigms important for JavaScript app developers?",
577 | type: "JavaScript",
578 | },
579 | {
580 | question: "What is functional programming?",
581 | type: "JavaScript",
582 | },
583 | {
584 | question: "What is the difference between classical inheritance and prototypal inheritance?",
585 | type: "JavaScript",
586 | },
587 | {
588 | question: "What are the pros and cons of functional programming vs object−oriented programming?",
589 | type: "JavaScript",
590 | },
591 | {
592 | question: "What are two−way data binding and one−way data flow, and how are they different?",
593 | type: "JavaScript",
594 | },
595 | {
596 | question: "What is asynchronous programming, and why is it important in JavaScript?",
597 | type: "JavaScript",
598 | },
599 | {
600 | question: "What is recursion and give an example using javascript?",
601 | type: "CS Theory",
602 | },
603 | {
604 | question: "What are types?",
605 | type: "CS Theory",
606 | },
607 | {
608 | question: "What are data structures?",
609 | type: "CS Theory",
610 | },
611 | {
612 | question: "What is an algorithm? ",
613 | type: "CS Theory",
614 | },
615 | {
616 | question: "What is scope / lexical scope in javascript?",
617 | type: "CS Theory",
618 | },
619 | {
620 | question: "What is polymorphism?",
621 | type: "CS Theory",
622 | },
623 | {
624 | question: "What is encapsulation?",
625 | type: "CS Theory",
626 | },
627 | {
628 | question: "What is a Linked List?",
629 | type: "CS Theory",
630 | },
631 | {
632 | question: "What is a Doubly Linked List?",
633 | type: "CS Theory",
634 | },
635 | {
636 | question: "What is a Queue?",
637 | type: "CS Theory",
638 | },
639 | {
640 | question: "What is a Stack?",
641 | type: "CS Theory",
642 | },
643 | {
644 | question: "What is a Hash Table?",
645 | type: "CS Theory",
646 | },
647 | {
648 | question: "What is a Heap?",
649 | type: "CS Theory",
650 | },
651 | {
652 | question: "What is a Trie?",
653 | type: "CS Theory",
654 | },
655 | {
656 | question: "What is a Tree?",
657 | type: "CS Theory",
658 | },
659 | {
660 | question: "What is a Binary Search Tree?",
661 | type: "CS Theory",
662 | },
663 | {
664 | question: "What is a Disjoint Set?",
665 | type: "CS Theory",
666 | },
667 | {
668 | question: "What is a Bloom Filter?",
669 | type: "CS Theory",
670 | },
671 | {
672 | question: "Demonstrate Bubble Sort and explain when you might use it.",
673 | type: "CS Theory",
674 | },
675 | {
676 | question: "Demonstrate Insertion Sort and explain when you might use it.",
677 | type: "CS Theory",
678 | },
679 | {
680 | question: "Demonstrate Merge Sort and explain when you might use it.",
681 | type: "CS Theory",
682 | },
683 | {
684 | question: "Demonstrate Quicksort and explain when you might use it.",
685 | type: "CS Theory",
686 | },
687 | ],
688 | };
689 |
--------------------------------------------------------------------------------
/js/main.js:
--------------------------------------------------------------------------------
1 | document.querySelector("#clickMe").addEventListener("click", newQuestion);
2 |
3 | async function newQuestion() {
4 | await makeReq()
5 | document.querySelector("section").classList.add("animate__animated", "animate__bounceIn");
6 | document.querySelector("section").classList.remove("hidden");
7 | document.querySelector("section").addEventListener("animationend", () => {
8 | document.querySelector("section").classList.remove("animate__animated");
9 | document.querySelector("section").classList.remove("animate__bounceIn");
10 | });
11 | }
12 |
13 | async function makeReq() {
14 | const res = await fetch(`/api`);
15 | const data = await res.json();
16 | document.querySelector("#question").innerHTML = data.question;
17 | let qType = data.type;
18 | document.querySelector("#questionType").textContent = `${qType.charAt(0).toUpperCase() + qType.slice(1)}`;
19 | };
20 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "3dml2p",
3 | "version": "1.0.0",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "3dml2p",
9 | "version": "1.0.0",
10 | "dependencies": {
11 | "figlet": "^1.5.2"
12 | }
13 | },
14 | "node_modules/figlet": {
15 | "version": "1.5.2",
16 | "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.5.2.tgz",
17 | "integrity": "sha512-WOn21V8AhyE1QqVfPIVxe3tupJacq1xGkPTB4iagT6o+P2cAgEOOwIxMftr4+ZCTI6d551ij9j61DFr0nsP2uQ==",
18 | "engines": {
19 | "node": ">= 0.4.0"
20 | }
21 | }
22 | },
23 | "dependencies": {
24 | "figlet": {
25 | "version": "1.5.2",
26 | "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.5.2.tgz",
27 | "integrity": "sha512-WOn21V8AhyE1QqVfPIVxe3tupJacq1xGkPTB4iagT6o+P2cAgEOOwIxMftr4+ZCTI6d551ij9j61DFr0nsP2uQ=="
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "3dml2p",
3 | "version": "1.0.0",
4 | "description": "",
5 | "keywords": [],
6 | "main": "index.html",
7 | "type": "module",
8 | "dependencies": {
9 | "figlet": "^1.5.2"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | import http from "http";
2 | import fs from "fs";
3 | import url from "url";
4 | // import querystring from 'querystring'
5 | import figlet from "figlet";
6 | import { banki } from "./js/banki.js";
7 |
8 | const PORT = process.env.PORT || 8000
9 | const server = http.createServer((req, res) => {
10 | const readWrite = (file, contentType) => {
11 | fs.readFile(file, function (err, data) {
12 | res.writeHead(200, { "Content-Type": contentType });
13 | res.write(data);
14 | res.end();
15 | });
16 | };
17 |
18 | const page = url.parse(req.url).pathname;
19 | // const params = querystring.parse(url.parse(req.url).query);
20 | switch (true) {
21 | case page == "/":
22 | readWrite("index.html", "text/html");
23 | break;
24 | case page == "/api":
25 | const random = Math.floor(Math.random() * banki.questions.length);
26 | res.end(JSON.stringify(banki.questions[random]));
27 | break;
28 | case page == "/css/style.css":
29 | fs.readFile("css/style.css", function (err, data) {
30 | res.write(data);
31 | res.end();
32 | });
33 | break;
34 | case page == "/css/normalize.css":
35 | fs.readFile("css/normalize.css", function (err, data) {
36 | res.write(data);
37 | res.end();
38 | });
39 | break;
40 | case page == "/js/main.js":
41 | readWrite("js/main.js", "text/javascript");
42 | break;
43 | default:
44 | figlet("404!!", function (err, data) {
45 | if (err) {
46 | console.log("Something went wrong...");
47 | console.dir(err);
48 | return;
49 | }
50 | res.write(data);
51 | res.end();
52 | });
53 | break;
54 | }
55 | });
56 |
57 | server.listen(PORT);
58 |
--------------------------------------------------------------------------------