node.js

npm安装教程

和自甴很熟 提交于 2021-02-16 19:52:23
一、使用之前,我们先来掌握3个东西是用来干什么的。 npm: Nodejs下的包管理器。 webpack: 它主要的用途是通过CommonJS的语法把所有浏览器端需要发布的静态资源做相应的准备,比如资源的合并和打包。 vue-cli: 用户生成Vue工程模板。(帮你快速开始一个vue的项目,也就是给你一套vue的结构,包含基础的依赖库,只需要 npm install就可以安装) 开始: 如图,下载8.9.3 LTS (推荐给绝大部分用户使用) 双击安装 可以使用默认路径,本例子中自行修改为d:\nodejs 一路点Next 点Finish完成 打开CMD,检查是否正常 再看看另外2个目录,npm的本地仓库跑在系统盘c盘的用户目录了(没见到npm-cache是因为没有用过,一使用缓存目录就生成了),我们试图把这2个目录移动回到D:\nodejs 先如下图建立2个目录 然后运行以下2条命令 npm config set prefix "D:\nodejs\node_global" npm config set cache "D:\nodejs\node_cache" 如上图,我们再来关注一下npm的本地仓库,输入命令npm list -global 输入命令npm config set registry=http://registry.npm.taobao.org 配置镜像站

FISCO BCOS 控制台详解,飞一般的区块链体验

倾然丶 夕夏残阳落幕 提交于 2021-02-16 19:24:02
我们对Linux系统中的命令行终端已经很熟悉了,通过shell终端可以顺畅地使用Linux。 类似地,FISCO BCOS联盟链中,也有这样的命令行终端,称为控制台。 控制台是开发者探索区块链世界的助推器,其提供的各种功能有助于跨越横在区块链入门到精通之间的座座高山,带来“开箱即用”的顺滑体验。 Why: 为什么要做控制台? 体验环境影响用户从“入门到放弃”,或者“入门到精通”。 当学习一个新技术或产品时,除了读文档之外,尝试上手操作,获得第一手体验也尤为重要。 如果体验环境配置复杂、操作繁琐,很可能导致用户从“入门到放弃”; 而体验环境简单易配置、功能丰富,则会为用户迅速打开一扇新世界的大门,加速用户从入门到精通。 选择何种形式承载这种极速且友好的体验方式呢? 如果我们有一个控制台,只要输入单条命令或代码,然后按下回车键就可以返回结果显示在用户面前。 这种 “开箱即用”的效果,正是我们所期待的体验方式。 可以为FISCO BCOS实现极速体验的控制台吗? FISCO BCOS 1.3版本其实已经具备快速体验的功能,由两部分组成,分别是ethconsole和Node.js工具。 其中,ethconsole可以查询链上信息,包括节点、区块和交易信息; Node.js工具提供了部署和调用合约的模板js文件,协助用户实现合约的部署与调用。 但是这种体验方式还不够友好

Node.js - SyntaxError: Unexpected token * when import express

落花浮王杯 提交于 2021-02-16 18:28:08
问题 node: v10.16.3 npm: 6.12.0 I got a error when I import express in node. I'm using this code https://github.com/angular-university/rxjs-course, look at server/server.ts . I run server.ts with $ ts-node ./server/server.ts The related code is: import * as express from 'express'; The error is: import * as express from 'express'; ^ SyntaxError: Unexpected token * at Module._compile (internal/modules/cjs/loader.js:723:23) at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:493:23

TypeError: res.sendFile is not a function

痴心易碎 提交于 2021-02-16 18:00:19
问题 I am working through a basic MEAN tutorial, and I am already hitting a wall. Getting 'TypeError: res.sendFile is not a function' error //package.json { "name": "http-server", "main": "server.js", "dependencies": { "express": "^4.13.4" } } //server.js var express = require('express'); var app = express(); var path = require('path'); app.get('/', function (res, req) { res.sendFile(path.join(__dirname + '/index.html')); }); app.listen(1337); console.log('Visit me at http://localhost:1337'); 回答1:

TypeError: res.sendFile is not a function

ぃ、小莉子 提交于 2021-02-16 18:00:09
问题 I am working through a basic MEAN tutorial, and I am already hitting a wall. Getting 'TypeError: res.sendFile is not a function' error //package.json { "name": "http-server", "main": "server.js", "dependencies": { "express": "^4.13.4" } } //server.js var express = require('express'); var app = express(); var path = require('path'); app.get('/', function (res, req) { res.sendFile(path.join(__dirname + '/index.html')); }); app.listen(1337); console.log('Visit me at http://localhost:1337'); 回答1:

Enabling Cross Origin Resource sharing (CORS) in ExpressJS framework on NodeJS developed using Swagger

房东的猫 提交于 2021-02-16 17:56:42
问题 I've hosted a nodejs server on localhost generated using Swagger and I'm trying to make API calls to it using Swagger UI again hosted on localhost. The network profile in chrome is showing connection refused everytime I'm making a call because CORS header are not added to the request. This is my app.js file which was generated using Swagger: 'use strict'; var SwaggerExpress = require('swagger-express-mw'); var app = require('express')(); module.exports = app; // for testing var config = {

Lint warning for invoking an async function without `.then()` or `await` without TypeScript

限于喜欢 提交于 2021-02-16 17:56:16
问题 In TypeScript, it is possible to check and warn the developer if they are calling an async function synchronously. For those that want less overhead and using node.js v9.0+, is it possible to have any linter give us a warning if we have something like this? async function foo() { return; } var result = foo(); // warning right here because there is no await The reason being is that it is not apparently if a function is returning a promise/is await unless we explicitly name it fooAsync , look

Enabling Cross Origin Resource sharing (CORS) in ExpressJS framework on NodeJS developed using Swagger

纵然是瞬间 提交于 2021-02-16 17:55:11
问题 I've hosted a nodejs server on localhost generated using Swagger and I'm trying to make API calls to it using Swagger UI again hosted on localhost. The network profile in chrome is showing connection refused everytime I'm making a call because CORS header are not added to the request. This is my app.js file which was generated using Swagger: 'use strict'; var SwaggerExpress = require('swagger-express-mw'); var app = require('express')(); module.exports = app; // for testing var config = {

Mac下搭建react native开发环境

流过昼夜 提交于 2021-02-16 17:52:41
安装必需软件 Homebrew Homebrew , Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件。 /usr/bin /ruby -e "$(curl -fsSL https:/ /raw.githubusercontent.com/Homebrew /install/master /install)" homebrew在安装软件时可能会碰到 /usr/local 目录不可写的权限问题。可以使用下面的命令修复: sudo chown -R `whoami` /usr/ local Node 使用Homebrew来安装 Node.js . brew install node 注意有坑:查看安装的node是否最新版本,默认安装的不是最新版本(我以为默认给我了最新(v8.00),其实默认只给我安装了v4.0.0,v4.0.0不支持ES6,当下面用react-native init <Project> 时会报语法错误 解决方法: 1、安装完node后使用命令查看当前版本 node -v 2、然后查看最新版本 npm info node 3、升级node 清除node.js的cache: sudo npm cache clean -f 安装n工具,n是专门是管理node.js版本的 sudo npm install -g n 安装最新node版本 sudo n

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

孤者浪人 提交于 2021-02-16 16:37:07
问题 I am using nodejs server, express framework and fetch library to send request to another server which is in different domain. For one of my endpoint consider (localhost:8080/login) i am rendering ejs file when the user clicks login button i am sending a fetch request to an api (https:otherserver.com/login) different server which is in other domain. i am not able to send this request. I am getting this error : Response to preflight request doesn't pass access control check: No 'Access-Control