博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nodejs:在windows系统中安装node.js 及第一个程序Hello World
阅读量:4287 次
发布时间:2019-05-27

本文共 1127 字,大约阅读时间需要 3 分钟。

今天开始学习node.js,所以在windows 8 中安装了node.js,并不会遇到什么问题,

首先,你需要在nodejs.org中下载nodejs的windows 版本,

当前版本是v0.10.23,我下载了windows版的,并进行了安装。

其实很简单就安装这个文件:

node-v0.10.23-x86.msi,

你随便可以安装在那个目录都可以的,

安装完成后,环境变量会自动配好的,如果你要移动这个安装好的文件到其他的目录下面,你就的重新配置环境变量,

所以最好你之前就选好安装文件夹,现在就来测试下是都安装成功,打开命令窗口,输入node -v

会看到输出v0.10.23,就是版本号

在安装完成之后,按照惯例,先来一个Hello World 程序,所以例子也是直接拿来的代码:也是参考大神的。

var http = require("http");http.createServer(function (req, res) {    res.writeHead(200, { "Content-Type": "text/plain" });    res.end("Hello World \n");}).listen(8080, "127.0.0.1");console.log("Server running at http://127.0.0.1:8080/");

代码逻辑:

   1. 全局方法require()是用来导入模块的,一般直接把 require() 方法的返回值赋值给一个变量,在 JavaScript 代码中直接使用此变量即可 。require("http") 就是加载系统预置的 http 模块

   2. http.createServer 是模块的方法,目的就是创建并返回一个新的web server对象,并且给服务绑定一个回调,用以处理请求。

   3. 通过 http.listen() 方法就可以让该 HTTP 服务器在特定端口监听。

   4. console.log就不用多说了,了解firebug的都应该知道,Node实现了这个方法。

将这段代码保存在D:\hello.js中(随便一个路径就好了),然后在命令行中输入:

node D:\hello.js
会看到命令输出

好了,基本上已经完成了,接下来就是测试了,在浏览器中输入 http://127.0.0.1:8080,会看到输出hello world。

如果你也看到了和我一样的界面,说明你的nodejs已经安装正确了。开始接下来的学习吧。

如果要退出刚才写的helloworld程序,需要按CTRL+C来完成退出。

好啦,慢慢学习了。

你可能感兴趣的文章
论文笔记:Constructing Narrative Event Evolutionary Graph for Script Event Prediction
查看>>
论文笔记丨Open Hierarchical Relation Extraction
查看>>
论文笔记| BART:Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation
查看>>
【论文笔记】 | Learning to Retrieve Reasoning Paths over Wikipedia Graph for Question Answering
查看>>
论文笔记 | Adversarial Examples for Evaluating Reading Comprehension Systems
查看>>
2021-06-12
查看>>
论文笔记| The Emergence, Advancement and Future of Textual Answer Triggering
查看>>
论文笔记|Open Set Text Classification using Convolutional Neural Networks
查看>>
论文笔记: Hierarchical Chinese Legal event extraction via Pedal Attention Mechanism
查看>>
论文笔记 | Enhancing Pre-Trained Language Representations with Rich Knowledge for MRC
查看>>
论文笔记 | Text Summarization with Pretrained Encoders
查看>>
论文笔记:Document-level Event Extraction via Heterogeneous Graph-based Interaction Model with a Tracker
查看>>
论文笔记丨Inductive Unsupervised Domain Adaptation for Few-Shot Classification via Clustering
查看>>
论文笔记|GSum: A General Framework for Guided Neural Abstractive Summarization
查看>>
论文笔记 | Does Structure Matter? Encoding Documents for Machine Reading Comprehension
查看>>
论文笔记|Self-Supervised Test-Time Learning for Reading Comprehension
查看>>
论文笔记|Open-world Learning and Application to Product Classification
查看>>
论文笔记 _ ELECTRA_ Pre-training Text Encoders as Discriminators Rather than Generators
查看>>
【论文笔记】
查看>>
论文笔记:Exploring Pre-trained Language Models for Event Extraction and Generation
查看>>