- 浏览: 2552497 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
NODEJS(1)Some Introduction and helloworld
Some frameworks related node.js: Express, Geddy.
JavaScript and Node.js
JavaScript is not only the frontend things, and backend things are not only related to ruby, PHP, Java.
Server-side JavaScript
Node.js really is just another context: it allows you to run JavaScript code in the backend, outside a browser. Thus, Node.js is based on google V8 VM, and is really two things: a runtime environment and a library.
Install Node.js
Download the windows installer with this URL http://nodejs.org/dist/v0.6.12/node-v0.6.12.msi.
And the source code is here: http://nodejs.org/dist/v0.6.12/node-v0.6.12.tar.gz
Or we can get the source code from git
>git clone https://github.com/joyent/node.git nodejs
>cd nodejs
>git checkout v0.6.12
>vcbuild.bat // build on windows
>vcbuild.bat test
It is not wise to run these kind of commands on windows system. I just go with msi installation file. The install location is as follow:
C:\Program Files (x86)\nodejs, double click the exe file node.exe and type command to verify the installation
>process.versions
{ node: '0.6.12',
v8: '3.6.6.24',
ares: '1.7.5-DEV',
uv: '0.6',
openssl: '0.9.8r' }
>
Hello World Sample
find a file named helloworld.js and type in
console.log("Hello Karl");
run the application with command line
>node.exe helloworld.js
The Application Upload File
We want to serve web pages, therefore we need an HTTP server.
We need some kind of router in order to map requests to request handlers.
Request handlers.
Request data handling.
Upload handling.
Things are different with PHP/JAVA, we not only implement our application, we also implement the whole HTTP server.
A basic HTTP server
server.js holds all the server codes.
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
Run these file and visit http://localhost:8888, that is really amazing.
Analyzing our HTTP server
var http = require("http"); brings the http module in node.js with name http.
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
});
server.listen(8888);
The method createServer will create a server.
Passing functions around
function say(word){
console.log(word);
}
function execute(someFunction, value){
someFunction(value);
}
execute(say, "Good");
We can, as we just did, pass a function as a parameter to another function by its name.
How function passing makes our HTTP server work
var http = require("http");
function onRequest(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server = http.createServer(onRequest);
server.listen(8888);
We will refactor the codes like this.
Event-driven callbacks
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server = http.createServer(onRequest);
server.listen(8888);
Event-driven asynchronous server-side JavaScript with callbacks in action.
How our server handles requests
response.writeHead(200, {"Content-Type": "text/plain"}); // write head
response.write("Hello World"); // write body
response.end(); // response end here
Finding a place for our server module
var http = require("http");
function start() {
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server = http.createServer(onRequest);
server.listen(8888);
console.log("Server has started.");
}
exports.start = start;
We export the function start in server.js. We can use this module like this in index.js:
var server = require("./server");
server.start();
references:
http://www.iteye.com/topic/1114149
http://www.infoq.com/cn/articles/nodejs-frameworks
http://www.nodebeginner.org/
https://github.com/joyent/node/wiki/Installation
https://github.com/joyent/node
http://nodejs.org/
Some frameworks related node.js: Express, Geddy.
JavaScript and Node.js
JavaScript is not only the frontend things, and backend things are not only related to ruby, PHP, Java.
Server-side JavaScript
Node.js really is just another context: it allows you to run JavaScript code in the backend, outside a browser. Thus, Node.js is based on google V8 VM, and is really two things: a runtime environment and a library.
Install Node.js
Download the windows installer with this URL http://nodejs.org/dist/v0.6.12/node-v0.6.12.msi.
And the source code is here: http://nodejs.org/dist/v0.6.12/node-v0.6.12.tar.gz
Or we can get the source code from git
>git clone https://github.com/joyent/node.git nodejs
>cd nodejs
>git checkout v0.6.12
>vcbuild.bat // build on windows
>vcbuild.bat test
It is not wise to run these kind of commands on windows system. I just go with msi installation file. The install location is as follow:
C:\Program Files (x86)\nodejs, double click the exe file node.exe and type command to verify the installation
>process.versions
{ node: '0.6.12',
v8: '3.6.6.24',
ares: '1.7.5-DEV',
uv: '0.6',
openssl: '0.9.8r' }
>
Hello World Sample
find a file named helloworld.js and type in
console.log("Hello Karl");
run the application with command line
>node.exe helloworld.js
The Application Upload File
We want to serve web pages, therefore we need an HTTP server.
We need some kind of router in order to map requests to request handlers.
Request handlers.
Request data handling.
Upload handling.
Things are different with PHP/JAVA, we not only implement our application, we also implement the whole HTTP server.
A basic HTTP server
server.js holds all the server codes.
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
Run these file and visit http://localhost:8888, that is really amazing.
Analyzing our HTTP server
var http = require("http"); brings the http module in node.js with name http.
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
});
server.listen(8888);
The method createServer will create a server.
Passing functions around
function say(word){
console.log(word);
}
function execute(someFunction, value){
someFunction(value);
}
execute(say, "Good");
We can, as we just did, pass a function as a parameter to another function by its name.
How function passing makes our HTTP server work
var http = require("http");
function onRequest(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server = http.createServer(onRequest);
server.listen(8888);
We will refactor the codes like this.
Event-driven callbacks
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server = http.createServer(onRequest);
server.listen(8888);
Event-driven asynchronous server-side JavaScript with callbacks in action.
How our server handles requests
response.writeHead(200, {"Content-Type": "text/plain"}); // write head
response.write("Hello World"); // write body
response.end(); // response end here
Finding a place for our server module
var http = require("http");
function start() {
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server = http.createServer(onRequest);
server.listen(8888);
console.log("Server has started.");
}
exports.start = start;
We export the function start in server.js. We can use this module like this in index.js:
var server = require("./server");
server.start();
references:
http://www.iteye.com/topic/1114149
http://www.infoq.com/cn/articles/nodejs-frameworks
http://www.nodebeginner.org/
https://github.com/joyent/node/wiki/Installation
https://github.com/joyent/node
http://nodejs.org/
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 478NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 312Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 288NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 261Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 574NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 266Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 368Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 371Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
docker run --rm --name hello cogsmith/helloworld-nodejs # HELLOWORLD: 695144B4BC64 @ 2021-02-18T01:19:03.199Z 本地Web服务器@端口99 docker run -d --rm --name hellolocal --env PORT=9 -p 127.0.0.1:99:9 ...
本文将深入探讨“NodeJs windows 的 hello world”这个主题,旨在帮助初学者快速入门Node.js开发。 首先,让我们从创建一个简单的"Hello, World!"程序开始。在Node.js中,你可以通过创建一个名为`server.js`的文件...
nodejs-你好express hello world 应用程序的 Docker 镜像建造 $ sudo docker build -t hypercloud/nodejs-hello .跑步 $ sudo docker run -d -p 8080:8080 hypercloud/nodejs-hello
本文的主旨是通过一个简单的实例——输出“hello world”,来解析Node.js的基础使用方法。通过这个示例,我们可以了解到如何使用Node.js搭建基本的HTTP服务器,并处理简单的GET请求。 首先,Node.js通过require语句...
在 `01-introduction` 目录下创建一个名为 `01-hello-world.js` 的文件。可以使用文本编辑器如 Vim 进行创建和编辑: ```bash touch 01-hello-world.js vim 01-hello-world.js ``` 在打开的编辑器中输入以下内容: `...
文章的源代码http://blog.csdn.net/wang_situ/article/details/39896233 欢迎nodejs学习者下载,高手可忽略
【标题】:“hello-world-nodejs:NodeJS Hello World示例” 在编程世界中,"Hello, World!"程序是初学者入门的典型例子,它展示了如何在特定编程语言中执行最基础的输出操作。在这个名为“hello-world-nodejs”的...
这是一个用NodeJS编写的最小的hello world应用程序,用于测试目的。 TL; DR Docker撰写 $ curl -LO https://raw.githubusercontent.com/node-helloworld/node-helloworld-docker/master/docker-compose.yml $ ...
本篇文章将详细讲解如何在Linux系统下安装和配置Node.js,并通过一个简单的"Hello World"程序进行验证。 首先,确保你的Linux系统上已经安装了Python。Python是Node.js安装过程中必要的组件,特别是版本要求在v...
标题中的“huynn109-nodejs-helloworld:nodejs helloworld heroku”指的是一个开源项目,该项目是为了演示如何在Heroku云平台上部署一个简单的Node.js应用。Node.js是一个基于Chrome V8引擎的JavaScript运行环境,它...
这个"nodejs-helloworld"项目就是一个入门级的示例,用于展示如何在Node.js中创建一个简单的“Hello, World!”应用程序。让我们深入了解一下这个项目和相关的知识点。 **Node.js基础** Node.js的核心特性是其非阻塞...
在此存储库中,您将找到转换或创建Alexa Skill作为NodeJS Express应用程序准备在Kubernetes上运行所需的所有资源。 这些是您可以在kubernetes上运行Alexa Skill的两个可能选项: 1.使用Mongo Atlas云架构 2.使用...
使用Kubernetes的Node.js helloworld应用 eval $(minikube docker-env) 稍后,当您不再希望使用Minikube主机时,可以通过运行eval $(minikube docker-env -u)撤消此更改。 eval $(minikube docker-env) 要启动...
"learning-nodejs-hello"项目是为初学者设计的,旨在帮助他们理解和入门Node.js的基本概念和用法,通过创建一个简单的"Hello World"程序来开始。 Node.js是由Ryan Dahl在2009年开发的,它基于Google的V8引擎,能够...
标题 "nodejs-helloworld" 指的是一个基于 Node.js 的简单示例项目,它用于初学者学习如何在 Node.js 环境中创建基本的 "Hello, World!" 应用程序。Node.js 是一个开源的、跨平台的 JavaScript 运行环境,允许开发者...
你好,openshift-nodejs Hello World for Openshift 这是在Openshift中使用的示例Node.js应用程序
nodejs老版本,10.24.1
当有请求到达时,服务器返回 "Hello World!" 和请求的 URL。 3. 启动 NodeJS 命令提示符。有两种方法: - 通过桌面快捷方式 "node.js command prompt" 直接打开。 - 或者在开始菜单中搜索 "cmd",打开命令提示符...