Node.js

  1. how to install an npm mudule
  2. how to use the lite server npm module to serve up the contents of our project folder (so that it can be viewed in a browser)
  3. set up .gitignore (come folders can be excluded from being checked in to our git repository)

Initializing package.json
  • At the command prompt in your project folder, type,

npm init
  • accept the default values for most of the entries, except set the entry point to index.html
  • you will see a package.json file in your project folder
  • Installing an NPM Module

    • Install an NPM module, lite-server, that allows you to run a Node.js based development web server and serve up your project files. To do this, type the following at the prompt:
    npm install lite-server --save-dev
    
  • Next, open package.json in your editor and modify it as shown below. Note the addition of two lines, line 7 and line 9.
  • {
      "name": "git-test",
      "version": "1.0.0",
      "description": "This is the Git and Node basic learning project",
      "main": "index.html",
      "scripts": {
        **"start": "npm run lite",**
        "test": "echo \"Error: no test specified\" && exit 1",
        **"lite": "lite-server"**
      },
      "repository": {
        "type": "git",
        "url": "git+https://jogesh_k_muppala@bitbucket.org/jogesh_k_muppala/git-test.git"
      },
      "author": "",
      "license": "ISC",
      "homepage": "https://bitbucket.org/jogesh_k_muppala/git-test#readme",
      "devDependencies": {
        "lite-server": "^2.2.2"
      }
    }
    
  • Next, start the development server by typing the following at the prompt:
  • npm start
    
  • This should open your index.html page in your default browser.
  • If you now open the index.html page in an editor and make changes and save, the browser should immediately refresh to reflect the changes.
  • Setting up .gitignore

    • Next, create a file in your project directory named .gitignore (Note: the name starts with a period)Then, add the following to the .gitignore file
    node_modules
    
  • The do a git commit and push the changes to the online repository. You will note that the node_modules folder will not be added to the commit, and will not be uploaded to the repository.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值