node笔记(1)-环境介绍

参考node环境搭建
在终端输入

$ node -v
v11.12.0

然后用自己习惯的编辑器创建一个server.js,输入如下:

var http = require('http')
var server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-type': 'text/html'})
  res.end('<marquee behavior="SCROLL" direction="LEFT" bgcolor="#dddddd" height="30" width="150" hspace="0" vspace="0" loop="INFINITE" scrollamount="30" scrolldelay="500">Hello</marquee>')
})
server.listen(3000)

使用如下命令启动服务

node server.js

在浏览器中输入http://localhost:3000 会看到一个marquee标签的动画

NPM

新建一个文件夹

$ mkdir my-project
$ cd my-project/
$ npm init  //初始化node工程,生成一个package.json文件,项目配置文件
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 json` 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: (my-project) colorword
version: (1.0.0) 
description: 打印彩色字体
entry point: (index.js) app.js
test command: 
git repository: 
keywords: 
author: pang
license: (ISC) 
About to write to /Users/zhangsan/Documents/nodeDir/my-project/package.json:

{
  "name": "colorword",
  "version": "1.0.0",
  "description": "打印彩色字体",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "pang",
  "license": "ISC"
}


Is this OK? (yes) 

$ npm install colors

安装完毕my-project目录结构如下:
在这里插入图片描述
新建一个app.js文件:

$ vi app.js
require('colors')
console.log('hello wolor'.rainbow)
$ node app.js 

运行结果如下:
在这里插入图片描述

上传NPM模块

将自己的模块发布出去,首先在https://www.npmjs.com注册一个账户,执行如下命令

$ npm adduser 

验证账户密码,如果遇到npm ERR! code E409,可能是registry选项替换成了淘宝的镜像,解决办法:

$ npm login --registry http://registry.npmjs.org

然后执行:

$ npm publish
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值