美文网首页
Node工程快速入门

Node工程快速入门

作者: 明训 | 来源:发表于2021-04-23 21:17 被阅读0次

    背景说明

    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 bashcmd好用一些,不仅在样式上,git bash还支持sshlscpmvvi这些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
    $
    

    相关文章

      网友评论

          本文标题:Node工程快速入门

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