美文网首页
NodeJS 理解 & 入门

NodeJS 理解 & 入门

作者: _chuuuing_ | 来源:发表于2018-04-20 20:01 被阅读0次

我的第一个nodeJS

  1. install
  2. 安装路径一般如下


    安装路径
  3. 用户可选择代码文件位置,比如放D:\Users\c.he\Documents\nodejs目录下
  4. 在该目录下写第一个文件 server.js:
var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(8888);
  1. 打开命令行 > 去到server.js位置 > 输入 node server.js > 在浏览器中打开http://localhost:8888/
    cmd
    结果

cmd

node -v OR node --version check version of nodeJS

npm

npm全名node package manager,安装nodeJS时被自动安装到电脑上。 我们可以通过命令行来使用npm。

使用方法:To use npm, you need to open a command, switch to the directory in which you want to use it, and type npm plus the command you with to execute.
npm的核心功能很少,但他有无数个libraries(也就是nodeJS中的modules

查看所有npm命令 npm help

image.png

举例: 用npm添加一个libraries(modules 随便你怎么叫) - express npm install express

npm install express
C:\Users\c.he\Documents\nodejs路径下可以看到一个 node_modules文件,打开能找到express文件 ==> library express安装成功 .

( node_modules will also hold all future modules that you install for your current project using npm.)

举例:在程序中使用express这个library

const express = require('express')
const app = express();
app.get('/', function(req, res) {
    res.send('Hello World');
});
app.listen(8888, function() {
    console.log('app is listing to port 3000')
});
结果
同时因为console.log()语句,我们可以在cmd中看到:
cmd

src

知乎 如何学习node.js
node.js 入门
Understanding node.js
getting started with nodejs on windows
express应用

相关文章

  • NodeJS 理解 & 入门

    我的第一个nodeJS install 安装路径一般如下安装路径 用户可选择代码文件位置,比如放D:\Users\...

  • nodejs学习笔记-1 安装

    nodejs入门-安装 nodejs是什么,刚接触了一段时间,我自己也说不清楚它。按我个人的简单理解,nodejs...

  • React Native的极简手册

    安装入门 安装入门可以参考:React Native官方文档。 NodeJS知识储备:参考《NodeJS入门》。(...

  • Node入门到入门(Windows)

    Node入门到入门(Windows) 安装NodeJS和NPM 1.安装NodeJS和NPM ​ 打开...

  • nodejs入门

    nodejs入门 花了点时间整理了下nodejs入门的图谱,如果将整个图谱的点都过了一次,相信你的nodejs知识...

  • NODE.JS

    入门 NODE安装 http://www.runoob.com/nodejs/nodejs-install-set...

  • nodejs 学习路线

    <1--nodejs入门> 1.准备-- js语言入门: -- JavaScript 教程 ...

  • 库&插件&框架&工具

    nodejs 入门 nodejs 入门教程,大家可以在 github 上提交错误2016 年最好用的表单验证库 S...

  • Node.js文档和教程

    七天学会NodeJS:https://nqdeng.github.io/7-days-nodejs/Node入门:...

  • nodejs 到底是什么?

    理解 NodeJs Nodejs 自己使用了Openssl.在Nodejs 0.6之前, Nodejs是动态链接到...

网友评论

      本文标题:NodeJS 理解 & 入门

      本文链接:https://www.haomeiwen.com/subject/axnuoxtx.html