简体   繁体   English

如何在我的网页上部署我的Nodejs应用程序?

[英]How to deploy my Nodejs application on my webpage?

Made a very simple Timestamp Microservice app with node that I want to be able to run on a webpage on my website. 制作了一个非常简单的带有节点的Timestamp Microservice应用程序,我希望该节点可以在我网站的网页上运行。 How would I go about doing this? 我将如何去做呢? It currently works fine on my local server. 目前在我的本地服务器上工作正常。

I feel like this would be very simple but from searching can only find how to deploy to Heroku/AWS. 我觉得这很简单,但是通过搜索只能找到如何部署到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');
});

is you want to push this online on your own server, it will be the same as you did in local. 您是否要在自己的服务器上将其在线推送,将与本地服务器相同。

Install your server, install npm/node, push your project on it and run npm start. 安装服务器,安装npm / node,在其上推送项目,然后运行npm start。 This will work. 这将起作用。

If you want something a bit better for production, you can use a proxy webserver, like apache or nginx and run your nodejs project with pm2 如果您想要更好的产品,可以使用apache或nginx等代理Web服务器,并在pm2上运行nodejs项目

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

Heroku is the easiest deployment platfrom when it comes to node.js application. Heroku是涉及node.js应用程序的最简单的部署平台。 You can host it for free too. 您也可以免费托管它。 Checkout the url below. 在下面查看网址。

https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM