2017-08-06 9 views
0

非常にシンプルなTimestamp Microserviceアプリケーションを、自分のウェブサイト上のWebページで実行できるノードにしました。これをどうやってやりますか?現在のところ、私のローカルサーバー上で正常に動作します。私のWebページにNodejsアプリケーションを配備するには?

私はこれが非常に簡単だと思っていますが、検索からはHeroku/AWSに展開する方法しか見つけることができません。

const express = require('express'); 
const bodyParser = require('body-parser'); 
const cors = require('cors'); 

//Create an instance of Express for the app and instantiate bodyParser and cors 
const app = module.exports = express(); 
app.use(bodyParser.json()); 
app.use(cors()); 

app.get(`/dateValues/:dateVal`, (req,res,next) => { 
    //gets date from request 
    var dateVal = req.params.dateVal; 

    //Options for formatting date in natural state 
    var options = { year: 'numeric', month: 'long', day: 'numeric' }; 

    if(isNaN(dateVal)) { 
    var naturalDate = new Date(dateVal); 
    naturalDate= naturalDate.toLocaleDateString('en-US', options); 
    var unixDate = new Date(dateVal).getTime()/1000-21600; 

    } else { 
    var unixDate = dateVal; 
    var naturalDate = new Date((parseInt(dateVal)+21600)*1000); 
    naturalDate= naturalDate.toLocaleDateString('en-US', options); 
    } 
    res.json({unix: unixDate, natural: naturalDate}); 
}); 

app.listen(3000,() => { 
    console.log('App is running'); 
}); 

答えて

0

あなたは自分のサーバーでこれをオンラインにプッシュしたいのですが、それはあなたがローカルで行ったのと同じです。

サーバをインストールし、npm/nodeをインストールし、プロジェクトをプッシュしてnpm startを実行します。これは動作します。

それが来るとき、あなたが生産のために少しよりよい何かをしたい場合は、あなたがapacheやnginxのように、プロキシWebサーバを使用して

https://www.phusionpassenger.com/library/walkthroughs/deploy/nodejs/ownserver/nginx/oss/trusty/deploy_app.html

関連する問題