Getting error while running simple javascript using node framework

前端 未结 8 1989
闹比i
闹比i 2021-01-30 06:25

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

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

I\'m getting the following as a

相关标签:
8条回答
  • 2021-01-30 07:09

    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

    0 讨论(0)
  • 2021-01-30 07:11

    Brandon Helwig is 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.

    Fix

    sudo apt-get remove node 
    

    This will remove the accidentally installed package. Both names for the package node and nodejs are the same which is 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 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.js in your application.

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

    0 讨论(0)
提交回复
热议问题