My environment: MacOS Mojave
I created a VueJS application from their templates using
vue init pwa frontend
? Project name frontend
? Project short name: fewer than 12 characters to not be truncated on homescreens (default: same as name)
? Project description A Vue.js project
? Author me#myemail.com
? Vue build runtime
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Setup unit tests with Karma + Mocha? No
? Setup e2e tests with Nightwatch? No
yarn
yarn dev
That worked fine. The page ran on localhost:8080 and closed when ctrl-c.
I then built it for production
yarn build
I wrote a quick JS server to launch the contents from the dist/ folder to see what it looks like after building it.
const ora = require('ora')
const chalk = require('chalk');
const express = require('express');
const port = process.env.PORT || 8080;
const app = express();
const spinner = ora(chalk.yellow("Your application is starting..."));
spinner.start();
var delay = ( function() {
var timer = 0;
return function(callback, ms) {
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
app.use(express.static(__dirname + "/dist/"));
app.get(/.*/, function(req, res) {
res.sendFile(__dirname + "/dist/index.html");
});
app.listen(port);
delay(function() {
app.use(express.static(__dirname + "/dist/"));
app.get(/.*/, function(req, res) {
res.sendFile(__dirname + "/dist/index.html");
});
}, 3000);
spinner.stop();
console.log(chalk.cyan("Your application is running here: ") + ("http://localhost:8080"));
I run the server node server.js
However when I ctrl-c it kills the script however the application is still running on localhost:8080
I have tried sudo lsof -i tcp:8080 and netstat -vanp tcp | grep 8080 and they both returned nothing. Which leaves me with the following question: How do I stop this from listening on port 8080?
If anyone was wondering, I found out the problem. I had to go to chrome://serviceworker-internals and chrome://appcache-internals. I did a search for localhost:8080 and killed those serviceworkers.
I hope this helps whoever this happens to next!
Related
it's been more than a day and im stuck on this, please help!
So : I have this hoster that use Phusion Passenger for the NodeJS environnement and i want to run my Strapi App on it.
For now ive did the following :
Strapi and the node modules are installed on the server
The app is connected to the database
the app.js can start fine
The problem is here, i don't know how to configure my app.js file to make it launch Strapi
i did something like this but im pretty sure this is wrong :
const http = require("http");
const hostname = "127.0.0.1";
const port = "passenger";
const strapi = require("#strapi/strapi");
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello World! NodeJS");
});
server.listen(port, hostname, () => {
console.log(`Server running at https://somary.fr/`);
strapi().start();
});
How do i configure my app.js file to finally access my strapi app ?
I wrote a program of node js on Brackets Text Editor and saved it with name first.js. When I am executing it with command prompt using -
node first.js
var http = require('http');
function onRequest(req,res)
{
res.writeHead(200,{'Content-Type':'text/plain'});
res.write('hello js');
res.end();
}
http.createServer(onRequest).listen(8080);
It is running fine but when I am trying to run it on the localhost, it is not working.
The program that I wrote was -
If you did try localhost:8080 and that still doesn't work, it could be that some other program is running on that port. Try .listen(3000) then visit localhost:3000.
you can create a simple http server using express (be sure that u have the packaged installed , you can install express using npm : npm install express) .
your server.js code is :
const express = require("express");
const app = express();
const port = process.env.PORT || 4000;
app.get("/", (req, res) => {
console.log("response");
});
app.listen(port, () => {
console.log("Server listining on port ", port);
});
lets say you save this file in c:/folder , open cmd in the same folder
run : node server.js .
now go to your browser and check : http://localhost:4000/
I am new in nodejs,In server (using ssh) i installed node (expressjs) and npm on server successfully,
In app.js i put following code
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('<html><body><h1>Hello World</h1></body></html>');
});
var server = app.listen(3000, function () {
console.log('Node server is running..');
});
In xshell (command prompt) displaying message
"ubuntu#ip-***-**-*-***:~/admin/$ node app.js
Node server is running.."
Now i want to see Hello world in browser,How can i do this ?
For example my hostname is 11.111.11.111
and ip (displaying by xshell) is 222-22-2-222
And in ftp i put my code inside following directory
/home/ubuntu/admin
I just want to know that how can i see output in browser ? I tried with following urls but not worked for me
(hostname)
**.***.**.***/admin:3000
This should be working:
**.***.**.***:3000/admin
Note that the requests follow the format:
host:port/directory
I can't seem to use Express.js to serve up my frontend Angular2 app. It just keeps serving index.html as text and the scripts don't appear to load.
Steps to reproduce:
npm install angular-cli -g
ng new ng2app && cd ng2app
npm install express --save && npm install
touch src/server.js
update server.js file
// src/server.js
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html')
})
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
Run the server
node src/server.js
# => Node app is running on port 5000
http://localhost:5000/
Problem
browser spits this out on the page and never does anything (i.e it doesn't load my front-end angular2 app)
{{#unless environment.production}} {{/unless}} Loading... {{#each scripts.polyfills}}{{/each}}
also on this page there are the following browser console errors
GET http://localhost:5000/ember-cli-live-reload.js
(index):19 GET http://localhost:5000/%7B%7B.%7D%7D
(index):21 Uncaught ReferenceError: System is not defined
What am I doing wrong? P.S there's nothing wrong with the angular front-end portion. I know this because doing npm start works and ng2app loads up just fine like its supposed to.
This is the minimum that I have from a seed project see: https://github.com/spboyer/quickstart-ng-cli
var express = require('express'),
path = require('path'),
fs = require('fs');
var app = express();
var staticRoot = __dirname + '/';
app.set('port', (process.env.PORT || 3000));
app.use(express.static(staticRoot));
app.use(function(req, res, next){
// if the request is not html then move along
var accept = req.accepts('html', 'json', 'xml');
if(accept !== 'html'){
return next();
}
// if the request has a '.' assume that it's for a file, move along
var ext = path.extname(req.path);
if (ext !== ''){
return next();
}
fs.createReadStream(staticRoot + 'index.html').pipe(res);
});
app.listen(app.get('port'), function() {
console.log('app running on port', app.get('port'));
});
To me it looks like you have not actually ran the angular cli build.
I have developed a Meteor app. I would like to package this app in the node-webkit app runtime for Chromium. I need the Meteor server process to run locally. How would I go about starting the Meteor server process when a user launches the node-webkit app?
I know I can start a NodeJS server instance with node-webkit like this:
server.js
#!/usr/bin/env node
require('http').createServer(function(req, res) {
res.writeHead(200, {'content-type': 'text/html'});
res.end('<h1>sup</h1>');
}).listen(9000, '127.0.0.1');
Then if I run:
$ nw ./
node-webkit will start the NodeJS server and launch the node-webkit instance. I'm not including the package.json file here, but it essentially just says look at http://127.0.0.1:9000.
So, how would I go about writing that server.js file to start the Meteor instance while the node-wekkit app is running?
Thanks for any thoughts.
First Bundle your meteor app meteor build --directory /your/node-webkit/project/ and use this code to start your app. But, packaging Meteor with node-webkit can be a little bit more complicated. First, you'll need a mongodb server running on your client computer or somewhere the client can connect anytime.
var path = require('path');
var child_process = require('child_process');
// change these
var PORT = 9000;
var ROOT_URL = 'http://localhost:'+PORT;
var MONGO_URL = 'mongodb://localhost:27017/my_app_db';
var NODE_BIN = '/usr/local/bin/node';
// install npm dependencies
var options = {cwd: path.resolve(__dirname, 'bundle/programs/server/')};
var installNpm = child_process.exec('npm install', options, onNpmInstall);
function onNpmInstall (err, stderr, stdout) {
if(err) throw new Error('could not install npm dependencies');
// start Meteor
var options = {
env: {PORT: PORT, MONGO_URL: MONGO_URL, ROOT_URL: ROOT_URL},
cwd: __dirname
};
var proc = child_process.spawn(NODE_BIN, ['bundle/main.js'], options);
proc.on('close', function (code) {
console.log('Meteor exited with code ' + code);
});
}
You must remove mongo related smart packages if you want a 100% client-side application.