развернуть модуль на удаленном сервере, на котором выполняется node.js - PullRequest
0 голосов
/ 22 декабря 2018

Я работаю над своим app.js в node.js - пытаюсь развернуть серверный скрипт.Многие тонкие модули node.js нуждаются в require («что-то»);Я использую NPM локально, который работает по требованию, так как модули хорошо видны в локальной структуре папок node_modules.но теперь я готов загрузить или связать с хозяином.Я не могу запустить npm на этом сервере.

const Hapi = require('hapi');
will result in
Error: Cannot find module 'hapi'
because I don't know how to copy/install/bundle/ftp files to my host.
Hapi is just an example. Most anything that has a require will need something on the host.
I used webpack to create a server side bundle.js but just sticking bundle.js under /node_modules doesn't do anything.
Most modules have a complex folder structure underneath --- I'm trying to avoid copying a ton of folders and files under /node_modules.  Ideally, I want to combine the modules into a bundle.js and have those modules visible to app.js
but I am open to other ideas.

Я еще не пробовал использовать веб-пакет для связывания app.js ВМЕСТЕ с различными модулями.Вам повезло с таким подходом?спасибо.

I've tried to upload hapi files a folder-ful at a time, reaching a new require('something') error at every step.


'use strict';
const Hapi = require('hapi'); // <-- how can I deploy hapi on my node.js server?
// Create a server with a host and port
const server=Hapi.server({
    host:'localhost',
    port:8000
});
// Add the route
server.route({
    method:'GET',
    path:'/hello',
    handler:function(request,h) {

        return'hello world';
    }
});

// Start the server
async function start() {

    try {
        await server.start();
    }
    catch (err) {
        console.log(err);
        process.exit(1);
    }

    console.log('Server running at:', server.info.uri);
};

start();

1 Ответ

0 голосов
/ 22 декабря 2018
    one approach that worked:  using webpack to bundle the back end js.
    thanks to 
    https://medium.com/code-oil/webpack-javascript-bundling-for-both-front-end-and-back- 
end-b95f1b429810

    the aha moment... run webpack to create bundle-back.js then
    tie bundle-back.js to my node server
    **You start your backend server with ‘bundle-back.js’ using:
        node bundle-back.js 

    In other words, include app.js in the bundle with the modules.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...