简体   繁体   English

我可以在我的网站中包含这个 JavaScript/NodeJS/express 应用程序吗?

[英]Can I include this JavaScript/NodeJS/express app in my website?

I followed a tutorial on how to make a register and login function for a website using NodeJS, express, MongoDB as database and EJS.我遵循了有关如何使用 NodeJS、express、MongoDB 作为数据库和 EJS 的网站注册和登录 function 的教程。 I included a simple HTML file where I would like to have an href that goes towards the register page.我包含了一个简单的 HTML 文件,我希望在其中有一个指向注册页面的 href。 The JavaScript I included runs the server on port:5000, or on this: (process.env.PORT) variable.我包含的 JavaScript 在端口:5000 或此:(process.env.PORT)变量上运行服务器。 Basically my question is how I can include this register and login feature on my website.基本上我的问题是如何在我的网站上包含此注册和登录功能。

btw the included HTML file is not my actual website, but is just an easy example and the JavaScript I included is not all there is to the register/login app.顺便说一句,包含的 HTML 文件不是我的实际网站,而只是一个简单的示例,我包含的 JavaScript 并不是注册/登录应用程序的全部内容。

 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> </head> <body> click on register below to go to the register page<br> <a href="">register</a> </body> </html>

 const express = require('express'); const expressLayouts = require('express-ejs-layouts'); const mongoose = require('mongoose'); const flash = require('connect-flash'); const session = require('express-session'); const passport = require('passport'); const http = require('http'); const app = express(); // Passport config require('./config/passport')(passport); // DB Config const db = require('./config/keys').MongoURI; // Connect to Mongo mongoose.connect(db, { useNewUrlParser: true}).then(() => console.log('MongoDB Connected...')).catch(err => console.log(err)); // EJS app.use(expressLayouts); app.set('view engine', 'ejs'); // Bodyparser app.use(express.urlencoded({ extended: false})); // Express Session app.use(session({ secret: 'secret', resave: true, saveUninitialized: true, })); // Passport middleware app.use(passport.initialize()); app.use(passport.session()); // Connect Flash app.use(flash()); // Global variables app.use((req, res, next) => { res.locals.success_msg = req.flash('succes_msg'); res.locals.error_msg = req.flash('error_msg'); res.locals.error = req.flash('error'); next(); }); // Routes app.use('/', require('./routes/index')); app.use('/users', require('./routes/users')); const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(`Service started on port ${PORT}`));

Node is a server-side technology so you cannot include it eg as a script file. Node 是一种服务器端技术,因此您不能将其包含在例如脚本文件中。 An option for hosting server-side apps is Heroku .托管服务器端应用程序的一个选项是Heroku

Also, usage depends a bit on whether it's a headless API or a traditional web app.此外,使用情况在一定程度上取决于它是无头 API 还是传统的 web 应用程序。

In order to deploy a nodejs application to an existing web server running PHP, a good way is you can create a subdomain and host the nodejs app on the server and then redirect the login and register feature to that subdomain.为了将 nodejs 应用程序部署到运行 PHP 的现有 web 服务器,一个好方法是您可以创建一个子域并在服务器上托管 nodejs 应用程序,然后将登录和注册功能重定向到该子域。

https://www.namecheap.com/support/knowledgebase/article.aspx/10202/48/how-to-install-nodejs-on-a-vps-or-a-dedicated-server https://www.namecheap.com/support/knowledgebase/article.aspx/10202/48/how-to-install-nodejs-on-a-vps-or-a-dedicated-server

The above link has a good tutorial of how to host a nodejs server to an existing cpanel website.上面的链接有一个很好的教程,介绍了如何将 nodejs 服务器托管到现有的 cpanel 网站。

I hosted the app (and now my entire website) on heroku, because netlify (the host for my website I used before) doesn't support nodeJS.我在 heroku 上托管了应用程序(现在是我的整个网站),因为 netlify(我之前使用的网站的主机)不支持 nodeJS。

暂无
暂无

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

相关问题 我是否应该在我的前端网站代码(通过 Firebase 托管)中包含我的 NodeJS/Express 服务器代码(托管在 Heroku 上)? - Should I include my NodeJS/Express server code (hosted on Heroku) with my front-end website code (hosted through Firebase)? 如何反序列化发布到我的NodeJS / Express Web应用程序的数组/对象? - How can I deserialize arrays/objects posted to my NodeJS/Express web app? 如何在Node.js和Express中更好地组织路线? - How can I organize my routes better in nodejs & express? 我可以为网站访问者启用JavaScript吗? - Can I enable JavaScript for my website visitors? 通过JavaScript将Jade mixins包含在Express应用中 - Include Jade mixins via JavaScript in an Express app 是否可以将我网站上的常规javascript和CSS函数包含到我的angularjs应用中? - Is it possible to include normal javascript and css functions from my website into my angularjs app? 如何将 javascript 包含到我的 Express.js 应用程序中,该应用程序也使用 socket.io? - How to include javascript to my Express.js app which also using socket io? 如何在Visualforce页面上的CSS中包含JAVASCRIPT - How can I include JAVASCRIPT in my CSS on my visualforce page Nodejs / Express - 启动我的应用程序:不推荐使用express.createServer() - Nodejs / Express - Launching my app: express.createServer() is deprecated 从angularjs访问我网站的nodejs Express API - Accessing nodejs Express API of my website from angularjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM