背景说明
Node环境安装完成后,这里创建一个简单的工程进行入门
解决方案
创建项目
创建目录nodedemo
$ mkdir nodedemo
86183@LAPTOP-CRFK470 MINGW64 /c
$ ls
nodedemo/
86183@LAPTOP-CRFFK470 MINGW64 /c
$ cd nodedemo/
86183@LAPTOP-CRFFK470 MINGW64 /c/nodedemo
$
初始项目
通过node init
命令初始化项目
86183@LAPTOP-CRFFK470 MINGW64 /c/nodedemo
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help init` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (nodedemo)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to C:\nodedemo\package.json:
{
"name": "nodedemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this OK? (yes)
86183@LAPTOP-CRFFK470 MINGW64 /c/nodedemo
$
经常用Git的可能都会觉得
git bash
比cmd
好用一些,不仅在样式上,git bash
还支持ssh
、ls
、cp
、mv
、vi
这些Linux
常见命令
可以看到生成了一个文件
86183@LAPTOP-CRFFK470 MINGW64 /c/nodedemo
$ ls
package.json
文件内容如下
{
"name": "nodedemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
ISC
开源协议参见文档:https://opensource.org/licenses/ISC
编写脚本app.js
var greeting='hello wold nodejs';
console.log(greeting)
项目运行
$ node app.js
hello wold nodejs
86183@LAPTOP-CRFFK470 MINGW64 /c/nodedemo
$
网友评论