Я работаю над своим 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();