Javascript 使用节点框架运行简单的javascript时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2424346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:16:11  来源:igfitidea点击:

Getting error while running simple javascript using node framework

javascriptnode.js

提问by Diogo Gomes

As I run this piece of code using node a.js:

当我使用node a.js以下代码运行这段代码时:

var sys = require('sys');
sys.puts('Hello, World');

I'm getting the following as an error

我收到以下错误

axconfig: port 1 not active

axconfig: port 2 not active

axconfig:端口 1 未激活

axconfig:端口 2 未激活

回答by Diogo Gomes

Warning: This is old but it might still work.

警告:这是旧的,但它可能仍然有效。

You didn't install node.js but the package node(that contains some other unrelated software) for your linux distro.

您没有安装 node.js,而是为您的 linux 发行版安装了包节点(包含一些其他不相关的软件)。

You can install node.js three ways: Using git, downloading the version file, or installing through the package manager, I recommend using the package manager for ease-of-use and the ability to easily update.

您可以通过三种方式安装 node.js:使用 git、下载版本文件或通过包管理器安装,我建议使用包管理器以方便使用和轻松更新。

Package Manager

包管理器

Check out Installing Node.js via Package Manager. It has instructions on how to install using the package manager of your preference.

看看通过软件包管理器安装Node.js的。它有关于如何使用您喜欢的包管理器进行安装的说明。

Direct Download

直接下载

Go the the downloads pageof node.js and download the package for your OS. Don't forget that, doing i this way, doesn't auto-update node.js later on!

转到node.js的下载页面并下载适用于您的操作系统的软件包。不要忘记,这样做我以后不会自动更新 node.js !

Source Compilation / git

源码编译/git

First you need git and a compiler, here is how you install them on debian/ubuntu (this depends on your package manager):

首先你需要 git 和一个编译器,下面是你在 debian/ubuntu 上安装它们的方法(这取决于你的包管理器):

sudo apt-get install git-core build-essential

(If you don't want to use git, you can download the source code from the website. You still need build-essential or equivalent for your OS.)

(如果您不想使用 git,可以从网站下载源代码。您的操作系统仍然需要 build-essential 或等效版本。)

Then go to a folder where the "node" repository will be placed, something like ~/projectsor ~/srcis good enough, and do this:

然后转到将放置“节点”存储库的文件夹,例如~/projects~/src足够好,然后执行以下操作:

git clone https://github.com/joyent/node.git

Then enter the node directory, configure it and build it.

然后进入node目录,配置并build。

cd node && ./configure && make

Everything should go well. Before installing node you can optionally run the tests to check for any problems:

一切都应该顺利。在安装节点之前,您可以选择运行测试以检查任何问题:

make test

You can finally install node, this allows you to run the node command anywhere in the system and the javascript libraries to be installed.

您最终可以安装 node,这允许您在系统中的任何位置运行 node 命令以及要安装的 javascript 库。

make install

...and we are done. You can test those lines of code using node-repl (node's REPL, think "interactive interpreter"), just type node-repl, quit with Ctrl+D.

......我们完成了。您可以使用 node-repl(节点的REPL,想想“交互式解释器”)测试这些代码行,只需键入node-repl按 Ctrl+D退出。

回答by Munipratap

axconfig: port 1 not active axconfig: port 2 not active

axconfig:端口 1 未激活 axconfig:端口 2 未激活

this problem no where related to nodejs.

这个问题与nodejs无关。

Do not install node using the command sudo apt-get install node, This will install radio package(node). this radio package requires axports to be active, which is not linked with nodejs

不要使用命令安装节点sudo apt-get install node,这将安装无线电包(节点)。这个无线电包需要 axports 处于活动状态,它与 nodejs 没有链接

So uninstall node from sudo apt-get remove node

所以卸载节点 sudo apt-get remove node

Manually Download nodejs from Hereor from GitHubbut make sure you install the stable branch(0.4.x).Unpack the nodejs.

此处或从GitHub手动下载 nodejs,但请确保安装稳定分支(0.4.x)。解压 nodejs。

For installing please follow the README.md

安装请按照 README.md

After installing then set the environment variables echo PATH=$PATH:/home/user/pathtonode/

安装好后设置环境变量 echo PATH=$PATH:/home/user/pathtonode/

回答by Brandon Helwig

you installed node, you want the package called nodejs

你安装了节点,你想要名为 nodejs 的包

回答by ninja

If you are on ubuntu, follow:

如果您使用的是 ubuntu,请按照以下步骤操作:

sudo apt-get update
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

You need to install nodejs and not node!

您需要安装 nodejs 而不是 node!

回答by Ziyan Junaideen

Brandon Helwigis correct. It just happened to me. In general, if you get this type of error, you have installed the wrong package. Here are more instructions for you to install one of the latest versions of Node.js.

布兰登海尔维格是对的。它只是发生在我身上。通常,如果您遇到此类错误,则说明您安装了错误的软件包。以下是有关安装 Node.js 最新版本之一的更多说明。

Fix

使固定

sudo apt-get remove node 

This will remove the accidentally installed package. Both names for the package nodeand nodejsare the same which is node.

这将删除意外安装的软件包。包node和 的两个名称nodejs相同,即node.

If you do sudo apt-get install node, what you would get is a old version. But thanks for Chris Lea, we got a PPA for this task.

如果你这样做sudo apt-get install node,你会得到一个旧版本。但是感谢 Chris Lea,我们为这项任务获得了 PPA。

sudo apt-get update
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

This should get you the latest version of Node.jsin your application.

这应该会为Node.js您提供应用程序中的最新版本。

If you are in need of an bleeding edge version, you can install from the source. But I think this is way cleaner.

如果您需要最新版本,可以从源代码安装。但我认为这更清洁。

回答by huip

This problem is occur in ubuntu,so I resolved this problem by git. Clone this new source from github and do following actions:

这个问题出现在ubuntu中,所以我通过git解决了这个问题。从 github 克隆这个新源并执行以下操作:

  1. Uninstall node

    sudo apt-get remove --pure node
    sudo apt-get clean

  2. Make install node

    git clone https://github.com/joyent/node.git
    cd node
    ./configure
    make
    make install

  1. 卸载节点

    sudo apt-get remove --pure node
    sudo apt-get clean

  2. 制作安装节点

    git clone https://github.com/joyent/node.git
    cd node
    ./configure
    make
    make install

Then this will be work well.

那么这将运作良好。

回答by astroanu

The easiest way is to remove the node installation first and then install npm. npm is the Node Package Manager, this will automatically install nodejs itself

最简单的方法是先卸载node安装,再安装npm。npm 是 Node Package Manager,它会自动安装 nodejs 本身

回答by Oliver Schafeld

If Node.js installation as suggested by ninja works for you (like on AWS Ubuntu):

如果 ninja 建议的 Node.js 安装适合您(例如在 AWS Ubuntu 上):

sudo apt-get update
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

you might still want to add node to your system path like this:

您可能仍想将节点添加到您的系统路径中,如下所示:

export PATH=/usr/bin/:$PATH

so you can type

所以你可以输入

node webapp.js

instead of

代替

/usr/bin/node webapp.js

Find your node installation path simply by typing

只需键入即可找到您的节点安装路径

which node