728x90
728x90

Routing is basically just serving the client the content that it has asked for. In web-based client/server applications, the client specifies the desired content in the URL, which includes the path and querystring (we'll go over these parts of a URL in more detail later).

 

Let's take our "hello world!" example and make it a bit more interesting. We'll make a really simple website consisting of a home page, an about page, and a "not found" page. For now, we'll keep things simple and just serve plaintext instead of HTML:

var http = require('http');

http.createServer(function(req,res){
		var path = req.url.replace(/\\/?(?:\\?.*)?$/,'').toLowerCase();
		switch(path) {
				case '':
						res.writeHead(200,{'Content-type':'text/plain' });
						res.end('Homepage');
						break;
				case '/about':
						res.writeHead(200,{'Content-type':'text/plain' });
						res.end('About');
						break;
				default:
						res.writeHead(404,{'Content-type' :'text/plain'});
						res.end("Not Found');
						break;
			}
}).listen(3000);
console.log('Server started on localhost:3000; press Ctrl-C to terminate....')$

In this example, we've created a simple routing mechanism using the http module in Node.js. We've defined three routes: the home page, the about page, and a default 404 page, and served plaintext content for each. This is just the beginning, and we can expand this mechanism to handle more complex routing scenarios and serve different types of content, like HTML, JSON, or images.

 

If you run this code, you'll find that you can now browse to the home page, http://localhost:3000, and the about page, http://localhost:3000/about.

 

Any querystrings will be ignored (so http://localhost:3000/?foo=bar will serve the home page), and any other URL (http://localhost:3000/foo) will serve the Not Found page.

 


  • So what exactly is routing and why is it important in client/server applications?
  • Routing is just serving the client the content that it has asked for. In web-based client/server applications, the client specifies the desired content in the URL, which includes the path and querystring. Routing is important in client/server applications because it allows the server to serve the client the correct content based on the client's request.
  • How do you actually implement routing in web-based client/server applications?
  • In web-based client/server applications, routing is implemented by parsing the path and querystring from the URL specified by the client and serving the appropriate content based on these values.
  • What exactly is the http module in Node.js used for?
  • The http module in Node.js provides functionality for creating and serving HTTP servers and clients.
  • How does the example code demonstrate the implementation of a simple routing mechanism?
  • The example code demonstrates the implementation of a simple routing mechanism by defining three routes (home page, about page, and 404 page) and serving plaintext content for each route. The http module is used to create an HTTP server that listens on port 3000 and handles incoming requests. The switch statement is used to match the requested path to one of the defined routes and serve the appropriate content.
  • Can the routing mechanism be expanded to handle more complex scenarios and different types of content?
  • Yes, the routing mechanism can definitely be expanded to handle more complex scenarios and different types of content. For example, different routes can be defined to serve HTML, JSON, or images, and more complex routing scenarios can be handled by using regular expressions or middleware to modify incoming requests or outgoing responses.

 

 

 


summary : 

Routing in web-based client/server applications involves serving the client the content it has requested by parsing the path and querystring from the URL. The http module in Node.js can be used to create a simple routing mechanism, as demonstrated in the example code, which can be expanded to handle more complex scenarios and different types of content.


comment:

Writing about routing in client/server applications was an interesting experience. It's fascinating to see how a simple mechanism can be used to serve different types of content to clients based on their requests. The http module in Node.js makes it easy to create a routing mechanism, and the example code provided a good starting point for understanding how routing works. 

728x90
300x250

'2023 공부한것들' 카테고리의 다른 글

[Node.js] Multer 모듈  (0) 2023.06.22
[node.js] 동기/비동기 한판 정리  (2) 2023.06.22
WIL : 20230614-20230618  (0) 2023.06.18
[node.js] es? (es5, es6)  (0) 2023.06.18
[node.js] making a simple web server with node  (0) 2023.06.18
728x90
728x90

recent TIL

https://insidepixce.tistory.com/85

that day was not perfect but pretty enough to satisfy myself. 

that means, i did try my best 

even though i worte a lot of plans and i didn't cleared them all, i tried to follow the timeline which i made

well. pretty cool .

 

[TIL] 20230614 : 노드 정복 걸음마

20230614 수요일 스터디 진행 (생활코딩 9장~ 22장) 스터디 준비 자바스크립트 강의 1주차부터 다시 정리하기 생활코딩 9장 ~22장 예상질문 정리내용 예상 질문 : 포트란 무엇인가??? 데이터를 주고 받

insidepixce.tistory.com

https://insidepixce.tistory.com/87

my mental health started to mess up everything from this day but still ok .

i learned many things that day.

 

 

[TIL] 20230615 개발일지

오늘의 타임테이블 5:00am 6:00am 7:00am 8:00am 9:00am 항해접속/ 2주차까지 한 필기 복습하면서 시험 준비 10:00am 항해 99 시험 11:00am 숫자야구게임 점검 12:00pm 점심시간 1:00pm 숫자야구게임코드리뷰 (13시 1

insidepixce.tistory.com

https://insidepixce.tistory.com/90

that was my first til in english. i'm not going to have more consideratiosns. 

only to head states. 

maybe headin uk would be better but imo i'm sure i would be addicted stayin my uk friends 

 

[TIL] 20230617 : killing my ocd

TIMELINE 5:00am 6:00am morning / getiing my meds 7:00am study module( fs) 8:00am study module (fs) 9:00am participate for presentation 10:00am ot with new team 11:00am study module (Fs) 12:00pm lunch 1:00pm til for yesterday 2:00pm write 24h 3:00pm individ

insidepixce.tistory.com

https://insidepixce.tistory.com/92

 

real burnout

that's fine, sometimes doing nothing is the best thing to do 

 

[TIL] 20230618 : what's your name?

what's your name? i'm hired you're hired? thanks, sir TIMELINE 5:00am 6:00am 7:00am 8:00am 9:00am 10:00am 11:00am 12:00pm 1:00pm 2:00pm 3:00pm 4:00pm doing some randome quests 5:00pm TIL of yesterday 6:00pm dinner 7:00pm console.log 8:00pm nothing but the

insidepixce.tistory.com


WIL MISSION

https://insidepixce.tistory.com/96

 

[node.js] es? (es5, es6)

ES stands for ECMAScript, which the standardized specification for scripting languages with JavaScript being the most popular implementation of ECMAScript. ECMAScript defines the syntax, semantics, and behavior of the Javascript programming language ES5 (E

insidepixce.tistory.com

 

bootcamp told me that i should include the summary bout es, and i posted it.

there's your link. i;'m not sure that i wrote that with perfect undestand, but i'm sure i learned a lot of things while posting.


comment

the main thing that i should overcome is my mental problem. not often but sometimes i just fall down and get into butnout mode. i should be able to control my emotions whenever i want to. i'm gonna try not to give affection to others easily. i should check iwhether they are enough wortthy. includes everyone except me

 

the solution of burnout must be the rest. but i don't want to take a rest. doing nothing makes me more unstable. I must find a point of agreement

 

728x90
300x250
728x90
728x90

ES stands for ECMAScript, which the standardized specification for scripting languages with JavaScript being the most popular implementation of ECMAScript. ECMAScript defines the syntax, semantics, and behavior of the Javascript programming language

ES5 (ECMAScript 5) was released in 2009 and brought several significant enhancements to JavaScript. Some notable features introduced in ES5 include:

  1. Strict Mode: ES5 introduced strict mode, which helps prevent common coding mistakes by enabling a stricter set of rules for JavaScript code.
  2. Function.prototype.bind: The bind method allows you to create a new function with a specific context (the this value) and pre-set arguments. It's useful for creating functions with a fixed context, particularly in event handlers.
  3. Array Methods: ES5 added several useful methods to the Array prototype, such as forEach, map, filter, reduce, and indexOf. These methods provide a more concise and functional programming-style approach to working with arrays.
  4. JSON: ES5 standardized the JSON object, providing methods like JSON.parse and JSON.stringify for parsing and stringifying JSON data.

ES6 (ECMAScript 2015), also known as ES2015, introduced many significant improvements and new features to JavaScript. Some key features introduced in ES6 include:

  1. Arrow Functions: Arrow functions provide a concise syntax for writing anonymous functions, with implicit returns and lexical scoping of this. They are especially useful for writing shorter and more readable code.
  2. let and const: ES6 introduced block-scoped variables let and const, which offer alternatives to the previously used var keyword. let allows declaring variables with block scope, while const is used for defining constants.
  3. Classes: ES6 introduced a more straightforward syntax for creating classes in JavaScript, using the class keyword. Classes provide a way to define object blueprints and create instances with shared methods and properties.
  4. Modules: ES6 introduced a standardized module system, allowing JavaScript code to be organized into separate files with explicit dependencies and exports. This promotes modularity and helps in building larger applications.
  5. Template Literals: Template literals provide an improved way to concatenate strings and embed expressions using backticks ( ``). They support multi-line strings and expression interpolation.
  6. Destructuring Assignment: Destructuring allows you to extract values from arrays or objects into individual variables, providing a concise way to access nested data structures.

These are just a few highlights of the features introduced in ES5 and ES6. Subsequent versions of ECMAScript, such as ES2016, ES2017, and so on, have brought further enhancements and new features to JavaScript.

728x90
300x250
728x90
728x90

a simple web server with node

[intro] simple web server with node-info

if you’ve ever built a static HTML website before, or are coming form a PHP or ASP background, you’re probably used to the idea of the web server (apache or iis) serving your static files so that a browser can view them over the network.

for example, if you create the file about.html , and put it in the proper directory, you can then navigate to `https://localhost/about.html , and put in the proper directory,depending on your web server configuration, you might even be able to omit the. html, but the relationship between url and filename is clear : the web server simply knows where the file is on the computer, and serves it to browser

*localhost, as the name implies, refers to the computer your’re on. This is a common alias for the IPv4 loopback adress::1. you will often see 127.0.0.1 used instead, but i will be using localhost in this. we can keep in mind that browsing to locahost will not connect to that computer*

node offers a different paradigm than that of a traditional web server : the ap that you write is the web server. node simply provides the framework for you to build a web server.

if you way you don’t want to write a web server, it’s a natural response ! you wnat to be writting an app, not a web server. however, node makes the business of writing this web server a simple affair( just a few lines, even ) and the control you gain over your application in return is more than worth it.

Hello world - making simple server

i’ve always found it unfotunate that the canonical introductory programming example is the uninspired message “HELLO WORLD"

even more, in korean, -llo(로) means go toward. that means hello world could be translated as lets go the hell, world!

actually it seems almost sacrilegious at this point to fly in the face of such ponderous tradition, so we’ll start there and move on.

examples

var http = require('http')

http.createServer(function(req.res){
	res.writeHead(200, {'content type': 'text/plain'});
}).listen(3000);

console.log('server started on localhost:3000; ...')

💥make sure you are in the same directory as helloworld.js and type node hello wolrd.js

open up a browser and navigate to http//localhost:3000 and , tada!

that’s a new web server. this particular one doesn’t serve HTML; rather, it just transmits the message “hello world” in plaintext to your browser. if you want, you can esperiment with sending HtmL instead : just text/plain to text/ html and change hello world to a string containing valid HTML. I didn’t demonstrate that, because i don’t like to wirte html inside javascript for reasons that will be discussed in more detail in other post

728x90
300x250

'2023 공부한것들' 카테고리의 다른 글

WIL : 20230614-20230618  (0) 2023.06.18
[node.js] es? (es5, es6)  (0) 2023.06.18
[node js] npm  (0) 2023.06.18
[TIL] 20230618 : what's your name?  (0) 2023.06.18
[node.js] console.log function  (0) 2023.06.17
728x90
728x90

NPM

npm: the ubiquitous pakage manager for Node packages

→ how we’ll get and install Express


HOW to get install npm

To get and install Express using npm, open a terminal and type npm install express. This will download the latest version of Express and install it in your project's node_modules

in the wry tradition of PHP, GNU , WINE and others, “npm” is not an acronym ; rather, it is a recursive abbreviation for npm is not an acronym.

broadly speaking, a package managers’s two primiary responsibilities are instaling packages and manging dependencies. npm is a fast, capacle, and painless package manager

which i feel is in large part responsible for the rapid growth and diversity of the Node ecosystem.


when does npm installed?

is installed when you install Node, so if you downloaded the node, you may got it

The primary command we use is npm , which means install

for example , to install Grunt (a popular Javascript task runner), you would issue the following command -

npm install -g grunt-cli

the -g flage tells npm to install the package globally

  • globally

it’s available globally on the system, anywhere

this distinction will become clrearer when we cover the package.json files. For now, the rule of thumb is that Javascript utilities (like Grunt) will generally be installed globally. whereas packages that are specific to your web app o project will not

💡 unlike languages like python- which underwent a major language change from 2.0 to 3.0, necessitating a way to easily swithch between different environments. - the node platform is new enough that it is. however, if you do find yourself needing to support multiple- version of node, there is a project, nvm that allows you to switch environments

let’s see the two ways how npm works

  1. local

if i don't choose other specific options, the package will be installed in local.

node_modules directory will be created in project root and the package will be installed in it.

local-installed packages can be only used in specific project

npm install <packagename>
  1. global

if you wanna install package in global way, you can put -g option.

it will install in global ways and it would make you to use that package on everywhere.

npm install -g <packagename>

for more, global-installed pacakage’sdownload place will be different depending on your os.

Mac: usr/local/lib/node_modules

window: c:\Users\%USERNAME%\AppData\Roaming\npm\node_modules

If you install the package in global way, it can be more comfortable to use it. but the fatal thing of this is : their info would not be written at package.json

for this, we can use -D option and install it devdependencies, and run it by npx command.

npm install -D nodemon
npm nodemon <packagename>

if you need some, there’s an analogy for you :


  • Development Team Leader: Controls the work efficiency of the development team and directs work to general employees.
  • Employee: A worker who is very diligent in whatever he is asked to do (?)

[ Scenario 1 ]

  • The development team leader instructs each of the three employees at the same time. ( = asynchronous )
  • Surprisingly, the development team leader doesn't even check what he ordered the 3 employees to do, and does his own work (= asynchronous)
  • Each employee completes the assigned task on their own and reports to the development team leader. ( = non-blocking )

[ Scenario 2 ]

  • The development team leader instructs employee 1 to work.
  • And until the work of employee 1 is over, it gives an eye to when it is over. ( = motive )
  • Employee 1's work is too slow, so he tries to give the job to another employee. ( = asynchronous )
  • However, employee 1 grabs the hem of the development team leader’s clothes asking for help. ( = blocking )
  • Employee 2 and Employee 3 who watch it are willing to work hard no matter what they are given, but there is no work. ( = motive )
728x90
300x250

'2023 공부한것들' 카테고리의 다른 글

[node.js] es? (es5, es6)  (0) 2023.06.18
[node.js] making a simple web server with node  (0) 2023.06.18
[TIL] 20230618 : what's your name?  (0) 2023.06.18
[node.js] console.log function  (0) 2023.06.17
[TIL] 20230617 : killing my ocd  (0) 2023.06.17
728x90
728x90

what's your name?

i'm hired

you're hired?

thanks, sir


TIMELINE


5:00am  
6:00am  
7:00am  
8:00am  
9:00am  
10:00am  
11:00am  
12:00pm  
1:00pm  
2:00pm  
3:00pm  
4:00pm doing some randome quests
5:00pm TIL of yesterday
6:00pm dinner
7:00pm console.log
8:00pm nothing but the best
9:00pm nothing but the best
10:00pm  
11:00pm  
12:00am  
1:00am  
2:00am  
3:00am  
4:00am  
5:00am  

 

what i did was.. almost nothing lol 

not the worst day on my life but only non-satisfied

 

well sometimes doing nothing can be the best way

no plans for today : think i'm in burnout


https://insidepixce.tistory.com/91

 

[node.js] console.log function

most Javascript systems (including node js) provide a console.log function that writes out its arguments to some text output device. In browsers, the output lands in the JavaScript console. The console.log function is a useful tool for debugging and unders

insidepixce.tistory.com

 

i should not keep in personal for everything they told 


only to be humbled and eagered, nothing to be serious. for more, talk empty. that's all i should do 

728x90
300x250

'2023 공부한것들' 카테고리의 다른 글

[node.js] making a simple web server with node  (0) 2023.06.18
[node js] npm  (0) 2023.06.18
[node.js] console.log function  (0) 2023.06.17
[TIL] 20230617 : killing my ocd  (0) 2023.06.17
[node.js] call stack (eng)  (0) 2023.06.17
728x90
728x90

most Javascript systems (including node js) provide a console.log function that writes out its arguments to some text output device. In browsers, the output lands in the JavaScript console.

The console.log function is a useful tool for debugging and understanding how your code is executing. You can use it to output the values of variables and objects, as well as to print messages to the console.

It's important to note that console.log should not be left in your production code, as it can slow down performance and may reveal sensitive information to users.

though building names cannot contain period characters, console.log does have one. This is because console.log isn’t a simple binding. it is actually an expression that retrieves the log property from the value held by the console binding.

This part of the browser interface is hidden by default, but most browsers open it when you press F12 or a command-option-I

\if that does not work, i think you got some another os, search in net.


The console.log function can also take multiple arguments, which will be printed out in a space-separated list.

For example,

 console.log('The answer is', 42)

this would output The answer is 42. You can also use string substitution to include values dynamically in your log messages, using %s as a placeholder for a string and %d for a number.

For example,

console.log(console.log('Hello, %s! You are visitor number %d.', 'ramona', 816)

would output Hello, Ramona! You are visitor number 816.

It's worth noting that console.log is not the only function available on the console object. Other useful functions include console.error for logging errors, console.warn for logging warnings, and console.info for logging information. Additionally, you can use console.table to output data in a tabular format, which can be useful for visualizing complex data structures.

728x90
300x250

'2023 공부한것들' 카테고리의 다른 글

[node js] npm  (0) 2023.06.18
[TIL] 20230618 : what's your name?  (0) 2023.06.18
[TIL] 20230617 : killing my ocd  (0) 2023.06.17
[node.js] call stack (eng)  (0) 2023.06.17
[TIL] 20230615 개발일지  (0) 2023.06.16
728x90
728x90

TIMELINE

5:00am  
6:00am morning / getiing my meds
7:00am study module( fs)
8:00am study module (fs)
9:00am participate for presentation
10:00am ot with new team
11:00am study module (Fs)
12:00pm lunch
1:00pm til for yesterday
2:00pm write 24h
3:00pm individual study
4:00pm solving algorism quiz
5:00pm solving algorism quiz
6:00pm solving algorism quiz
7:00pm pre-study for teamstudy
8:00pm pre-study for teamstudy
9:00pm teamstudy
10:00pm teamstudy
11:00pm teamstudy
12:00am teamstudy
1:00am individual study ⇒ gts
2:00am individual study → gts
3:00am archive → gts
4:00am  
5:00am  

Today was pretty hard day for me and my mental heath. my ocd was still pickin me. 

for more, i should find out the best way - cannot be perfect, but to be closest way to be perfect - to learn.

the certain thing is i should change the way to learn

i must be more humbled, and more eagered.

well, lets don't keep it personal. 


CHECKLIST

i did tried to do all of my plans but my mental health problem messed everything. actually i am obssesed with my meds ,juls and everyrthing else that makes my depression better

because i almost fell asleep after 4 i brewed myself a lot of caffeine and all i got was anxiety lol 

i must find few more ways to get high 


STUDY:  the call stack 

  https://insidepixce.tistory.com/89

 

[node.js] call stack (eng)

what’s call stack ? callstack : the way control flows through functions is somewhat involved. function greet(who) { console.log("Hello" + who); } greet("Ramona") console.log("Bye") run through this program goes roughly like this: → the call to greet ca

insidepixce.tistory.com

i got some few questions after writing this post

 

1. what happens when a function is called in javascript? how is the context stored on the call stack?

2. what is the significance of the call stack's role in function execution and returning to the calling location?

3. how does the call stack handle nested function calls and their corresponding contexts?

4. what error message will be thrown when the call stack becomes full and wht?

5. are there any ways to prevent or handle stack overflow errors in javascript?

6. are there any performance considerations or limitations related to the size of the call stack?

 

thats quite a lot, and i'll find it out tommorow.

 


TEAMSTUDY: package

https://elfin-verbena-bc2.notion.site/1-164ae273439d473c98b71fc8d5838de1?pvs=4 

 

1주차 금요일 스터디 일지

29. Package Manager & PM2

elfin-verbena-bc2.notion.site

third teaching plan For group study

first we studiied bout packages , npm and lot of things 

 

there was an  extremely impressive analogy:

package : the laundary machine with full package

npm :  delivery man

install : unpacking process

 

that was perfect alclogy 


for more

i just told my therapist that i got some really big problem about my sleep pattern. i do wanna life without pills but not now. taking pills makes me sleep long but i sleep to long with it. without pills, i got a lot of sudden wake-up. the point of agreement was making me extremely tired and fall asleep. am i doing right?

 

is that still entertaining?

 

 

728x90
300x250

+ Recent posts