[英]How to deploy my Nodejs application on my webpage?
制作了一個非常簡單的帶有節點的Timestamp Microservice應用程序,我希望該節點可以在我網站的網頁上運行。 我將如何去做呢? 目前在我的本地服務器上工作正常。
我覺得這很簡單,但是通過搜索只能找到如何部署到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');
});
您是否要在自己的服務器上將其在線推送,將與本地服務器相同。
安裝服務器,安裝npm / node,在其上推送項目,然后運行npm start。 這將起作用。
如果您想要更好的產品,可以使用apache或nginx等代理Web服務器,並在pm2上運行nodejs項目
Heroku是涉及node.js應用程序的最簡單的部署平台。 您也可以免費托管它。 在下面查看網址。
https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.