반응형


AWS : linux 에서 초기 세팅 및 npm , nodejs , 설치하기








    sudo yum update

This is going to take some time so be patient.



Yum package manager have no direct node.js or node repository so you need to manually download and compile the node.js binary package. This step will take some time so make sure you grab a coffee before starting.

1 : Install GCC++ and Make.

    sudo yum install gcc-c++ make

2 : Install openssl-dev.

    sudo yum install openssl-devel

3: Install git

    sudo yum install git

Execute these commands one by one and then run following.

1 : Download latest version of Node.js

    git clone git://github.com/nodejs/node.git

Switch to node folder.

    cd node

In order to install Node.js, you need to switch to latest branch of it. Current stable version at the time of writing this tutorial is v0.12.2.

Run this command to switch to branch.

git checkout v0.12.2

Run following command one by one.

./configure
make
sudo make install

Above steps will take around 10-15 minute to complete. Once done you should be able to use node.js in your Amazon EC2 system.

Install NPM :

Before installing any node modules in your system we need to add path where those modules should get installed. To do so, you need to edit sudoers file. Here is how to do so.

sudo su
vi /etc/sudoers

Once VI editor is opened, find this line.

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Once found, press “i” key to go in insert mode in VI and at the end of this line add following.

:/usr/local/bin

Or replace it with this.

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

In order to save your changes, press ESC key and type “wq” and hit ENTER in VI editor.

All right, let’s install NPM module.

1 : Clone the NPM.

git clone https://github.com/isaacs/npm.git

2 : Install the NPM.

cd npm
sudo make install

Wait for few minutes and you are done !

Say “Hello World”

Congratulations ! We have finally setup and install the Amazon EC2 and Node.js. It’s time to test the setup. Let’s create one simple project and print “Hello World”.

Create a new folder and switch to that folder. create package.json using VI and paste this code.

package.json
{
  "name": "sample",
  "version": "0.0.1",
  "dependencies": {
    "express": "^4.12.3"
  }
}





Run

npm install



실행했는데 이런 에러가 나면 (if you met this installing error)

npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY

npm config set registry http://registry.npmjs.org/  

이 명령줄을 실행한다



to install Express.

Create app.js file and paste following code.

app.js
var express = require("express");
var app = express();


app.get("/",function(req,res){
        res.send("<h1>Hello from EC2</h1>");
});

app.listen(80);

Run this app using following command.

sudo node app.js

Make sure you use SUDO for it. Visit your public DNS and you should see screen like this.

Conclusion :

Amazon is one of the best cloud provides and above all they let us try their System for free. You can use it to host your project, blog, website or anything. We have covered almost everything you need to get started but there are still some configuration left like mapping domains to EC2 instance. Will cover it later.




ref : https://codeforgeek.com/2015/05/setup-node-development-environment-amazon-ec2/

ref : https://stackoverflow.com/questions/45884752/npm-err-code-unable-to-get-issuer-cert-locally


반응형

+ Recent posts