Cannot Get/ in node.js The Next CEO of Stack OverflowHow do I debug Node.js applications?How do I get started with Node.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsWhat is the purpose of Node.js module.exports and how do you use it?How to get GET (query string) variables in Express.js on Node.js?Why this error coming while running nodejs server?how to do Users in express as this arrow function
What does this strange code stamp on my passport mean?
Simplify trigonometric expression using trigonometric identities
How can the PCs determine if an item is a phylactery?
Early programmable calculators with RS-232
Calculating discount not working
Airship steam engine room - problems and conflict
Incomplete cube
Upgrading From a 9 Speed Sora Derailleur?
Direct Implications Between USA and UK in Event of No-Deal Brexit
Mathematica command that allows it to read my intentions
Cannot restore registry to default in Windows 10?
Read/write a pipe-delimited file line by line with some simple text manipulation
Strange use of "whether ... than ..." in official text
Can Sri Krishna be called 'a person'?
Does int main() need a declaration on C++?
Does Germany produce more waste than the US?
Why doesn't Shulchan Aruch include the laws of destroying fruit trees?
What difference does it make matching a word with/without a trailing whitespace?
Can I cast Thunderwave and be at the center of its bottom face, but not be affected by it?
Masking layers by a vector polygon layer in QGIS
Could you use a laser beam as a modulated carrier wave for radio signal?
Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico
Is the offspring between a demon and a celestial possible? If so what is it called and is it in a book somewhere?
Is it reasonable to ask other researchers to send me their previous grant applications?
Cannot Get/ in node.js
The Next CEO of Stack OverflowHow do I debug Node.js applications?How do I get started with Node.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsWhat is the purpose of Node.js module.exports and how do you use it?How to get GET (query string) variables in Express.js on Node.js?Why this error coming while running nodejs server?how to do Users in express as this arrow function
I am following this http://www.expertphp.in/article/user-login-and-registration-using-nodejs-and-mysql-with-example link
I get a cannot GET/ error and I have tried all the stackoverflow answers but it isn't getting solved.
var express=require("express");
var bodyParser=require('body-parser');
var app = express();
var authenticateController=require('./controllers/authenticate-controller');
var registerController=require('./controllers/register-controller');
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
/* route to handle login and registration */
app.get('/', function (req, res)
res.render('index', );
);
app.post('/api/register',registerController.register);
app.post('/api/authenticate',authenticateController.authenticate);
app.listen(8012);
this is my current code
node.js express authentication get body-parser
add a comment |
I am following this http://www.expertphp.in/article/user-login-and-registration-using-nodejs-and-mysql-with-example link
I get a cannot GET/ error and I have tried all the stackoverflow answers but it isn't getting solved.
var express=require("express");
var bodyParser=require('body-parser');
var app = express();
var authenticateController=require('./controllers/authenticate-controller');
var registerController=require('./controllers/register-controller');
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
/* route to handle login and registration */
app.get('/', function (req, res)
res.render('index', );
);
app.post('/api/register',registerController.register);
app.post('/api/authenticate',authenticateController.authenticate);
app.listen(8012);
this is my current code
node.js express authentication get body-parser
The path/
is handled and returns an empty object. If you're really trying to get the error message, try remove the part of code where it says
app.get(...
– Kevin Pastor
Mar 21 at 20:32
add a comment |
I am following this http://www.expertphp.in/article/user-login-and-registration-using-nodejs-and-mysql-with-example link
I get a cannot GET/ error and I have tried all the stackoverflow answers but it isn't getting solved.
var express=require("express");
var bodyParser=require('body-parser');
var app = express();
var authenticateController=require('./controllers/authenticate-controller');
var registerController=require('./controllers/register-controller');
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
/* route to handle login and registration */
app.get('/', function (req, res)
res.render('index', );
);
app.post('/api/register',registerController.register);
app.post('/api/authenticate',authenticateController.authenticate);
app.listen(8012);
this is my current code
node.js express authentication get body-parser
I am following this http://www.expertphp.in/article/user-login-and-registration-using-nodejs-and-mysql-with-example link
I get a cannot GET/ error and I have tried all the stackoverflow answers but it isn't getting solved.
var express=require("express");
var bodyParser=require('body-parser');
var app = express();
var authenticateController=require('./controllers/authenticate-controller');
var registerController=require('./controllers/register-controller');
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
/* route to handle login and registration */
app.get('/', function (req, res)
res.render('index', );
);
app.post('/api/register',registerController.register);
app.post('/api/authenticate',authenticateController.authenticate);
app.listen(8012);
this is my current code
node.js express authentication get body-parser
node.js express authentication get body-parser
edited Mar 21 at 22:31
Zobia Kanwal
493320
493320
asked Mar 21 at 19:54
VISHAL ISRANIVISHAL ISRANI
61
61
The path/
is handled and returns an empty object. If you're really trying to get the error message, try remove the part of code where it says
app.get(...
– Kevin Pastor
Mar 21 at 20:32
add a comment |
The path/
is handled and returns an empty object. If you're really trying to get the error message, try remove the part of code where it says
app.get(...
– Kevin Pastor
Mar 21 at 20:32
The path
/
is handled and returns an empty object
. If you're really trying to get the error message, try remove the part of code where it says app.get(...
– Kevin Pastor
Mar 21 at 20:32
The path
/
is handled and returns an empty object
. If you're really trying to get the error message, try remove the part of code where it says app.get(...
– Kevin Pastor
Mar 21 at 20:32
add a comment |
2 Answers
2
active
oldest
votes
As far as I understand, you're trying to send index.html
at the path /
. That is fine, but don't use render
for that. Simply send index.html
as such:
// replace this
app.get('/', function (req, res)
res.render('index', );
);
// by this
app.get('/', (req, res) => res.sendFile('full/path/to/index.html'))
Useful links:
- Express doc on res.render
- Express doc on res.sendFile
add a comment |
You have 2 ways:
1) reading index.html
contents and serving it at root url:
const fs = require('fs');
const indexFileContent = fs.readFileSync('path/to/index.html'); // caching file content to variable, to avoid re-reading it
app.get('/', (req, res) =>
res.send(indexFileContent);
);
2) defining ejs
renderer as .html
file renderer too:
const path = require('path');
const bodyParser = require('body-parser');
const express = require("express");
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine','ejs'); // make sure You've installed ejs: npm i --save ejs
app.engine('ejs', require('ejs').renderFile);
app.engine('html', require('ejs').renderFile); // defining html renderer engine
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
app.get('/', (req, res) => res.render('index'));
// API controllers
const AuthController = require('./controllers/authenticate-controller');
const RegistrationController = require('./controllers/register-controller');
// API endpoints
app.post('/api/authenticate', AuthController.authenticate);
app.post('/api/register', RegistrationController.register);
app.listen(8012);
Pros-cons:
1-st example will simply read index.html once to variable and will serve that content, but will need restarting the app to re-read that file.
2-nd example is using .html
files inside views
folder as ejs
files, that gives opportunity to pass variables to html files which is better that simply sending files, + You can include one html inside of another using <% include partials/header.ejs %>
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like.sendFile
andstatic
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS/
route and compare sendFile vs cached content serving
– num8er
Mar 21 at 22:07
1
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288329%2fcannot-get-in-node-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As far as I understand, you're trying to send index.html
at the path /
. That is fine, but don't use render
for that. Simply send index.html
as such:
// replace this
app.get('/', function (req, res)
res.render('index', );
);
// by this
app.get('/', (req, res) => res.sendFile('full/path/to/index.html'))
Useful links:
- Express doc on res.render
- Express doc on res.sendFile
add a comment |
As far as I understand, you're trying to send index.html
at the path /
. That is fine, but don't use render
for that. Simply send index.html
as such:
// replace this
app.get('/', function (req, res)
res.render('index', );
);
// by this
app.get('/', (req, res) => res.sendFile('full/path/to/index.html'))
Useful links:
- Express doc on res.render
- Express doc on res.sendFile
add a comment |
As far as I understand, you're trying to send index.html
at the path /
. That is fine, but don't use render
for that. Simply send index.html
as such:
// replace this
app.get('/', function (req, res)
res.render('index', );
);
// by this
app.get('/', (req, res) => res.sendFile('full/path/to/index.html'))
Useful links:
- Express doc on res.render
- Express doc on res.sendFile
As far as I understand, you're trying to send index.html
at the path /
. That is fine, but don't use render
for that. Simply send index.html
as such:
// replace this
app.get('/', function (req, res)
res.render('index', );
);
// by this
app.get('/', (req, res) => res.sendFile('full/path/to/index.html'))
Useful links:
- Express doc on res.render
- Express doc on res.sendFile
answered Mar 21 at 21:38
Nino FiliuNino Filiu
2,90141528
2,90141528
add a comment |
add a comment |
You have 2 ways:
1) reading index.html
contents and serving it at root url:
const fs = require('fs');
const indexFileContent = fs.readFileSync('path/to/index.html'); // caching file content to variable, to avoid re-reading it
app.get('/', (req, res) =>
res.send(indexFileContent);
);
2) defining ejs
renderer as .html
file renderer too:
const path = require('path');
const bodyParser = require('body-parser');
const express = require("express");
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine','ejs'); // make sure You've installed ejs: npm i --save ejs
app.engine('ejs', require('ejs').renderFile);
app.engine('html', require('ejs').renderFile); // defining html renderer engine
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
app.get('/', (req, res) => res.render('index'));
// API controllers
const AuthController = require('./controllers/authenticate-controller');
const RegistrationController = require('./controllers/register-controller');
// API endpoints
app.post('/api/authenticate', AuthController.authenticate);
app.post('/api/register', RegistrationController.register);
app.listen(8012);
Pros-cons:
1-st example will simply read index.html once to variable and will serve that content, but will need restarting the app to re-read that file.
2-nd example is using .html
files inside views
folder as ejs
files, that gives opportunity to pass variables to html files which is better that simply sending files, + You can include one html inside of another using <% include partials/header.ejs %>
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like.sendFile
andstatic
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS/
route and compare sendFile vs cached content serving
– num8er
Mar 21 at 22:07
1
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
add a comment |
You have 2 ways:
1) reading index.html
contents and serving it at root url:
const fs = require('fs');
const indexFileContent = fs.readFileSync('path/to/index.html'); // caching file content to variable, to avoid re-reading it
app.get('/', (req, res) =>
res.send(indexFileContent);
);
2) defining ejs
renderer as .html
file renderer too:
const path = require('path');
const bodyParser = require('body-parser');
const express = require("express");
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine','ejs'); // make sure You've installed ejs: npm i --save ejs
app.engine('ejs', require('ejs').renderFile);
app.engine('html', require('ejs').renderFile); // defining html renderer engine
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
app.get('/', (req, res) => res.render('index'));
// API controllers
const AuthController = require('./controllers/authenticate-controller');
const RegistrationController = require('./controllers/register-controller');
// API endpoints
app.post('/api/authenticate', AuthController.authenticate);
app.post('/api/register', RegistrationController.register);
app.listen(8012);
Pros-cons:
1-st example will simply read index.html once to variable and will serve that content, but will need restarting the app to re-read that file.
2-nd example is using .html
files inside views
folder as ejs
files, that gives opportunity to pass variables to html files which is better that simply sending files, + You can include one html inside of another using <% include partials/header.ejs %>
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like.sendFile
andstatic
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS/
route and compare sendFile vs cached content serving
– num8er
Mar 21 at 22:07
1
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
add a comment |
You have 2 ways:
1) reading index.html
contents and serving it at root url:
const fs = require('fs');
const indexFileContent = fs.readFileSync('path/to/index.html'); // caching file content to variable, to avoid re-reading it
app.get('/', (req, res) =>
res.send(indexFileContent);
);
2) defining ejs
renderer as .html
file renderer too:
const path = require('path');
const bodyParser = require('body-parser');
const express = require("express");
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine','ejs'); // make sure You've installed ejs: npm i --save ejs
app.engine('ejs', require('ejs').renderFile);
app.engine('html', require('ejs').renderFile); // defining html renderer engine
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
app.get('/', (req, res) => res.render('index'));
// API controllers
const AuthController = require('./controllers/authenticate-controller');
const RegistrationController = require('./controllers/register-controller');
// API endpoints
app.post('/api/authenticate', AuthController.authenticate);
app.post('/api/register', RegistrationController.register);
app.listen(8012);
Pros-cons:
1-st example will simply read index.html once to variable and will serve that content, but will need restarting the app to re-read that file.
2-nd example is using .html
files inside views
folder as ejs
files, that gives opportunity to pass variables to html files which is better that simply sending files, + You can include one html inside of another using <% include partials/header.ejs %>
You have 2 ways:
1) reading index.html
contents and serving it at root url:
const fs = require('fs');
const indexFileContent = fs.readFileSync('path/to/index.html'); // caching file content to variable, to avoid re-reading it
app.get('/', (req, res) =>
res.send(indexFileContent);
);
2) defining ejs
renderer as .html
file renderer too:
const path = require('path');
const bodyParser = require('body-parser');
const express = require("express");
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine','ejs'); // make sure You've installed ejs: npm i --save ejs
app.engine('ejs', require('ejs').renderFile);
app.engine('html', require('ejs').renderFile); // defining html renderer engine
app.use(bodyParser.urlencoded(extended:true));
app.use(bodyParser.json());
app.get('/', (req, res) => res.render('index'));
// API controllers
const AuthController = require('./controllers/authenticate-controller');
const RegistrationController = require('./controllers/register-controller');
// API endpoints
app.post('/api/authenticate', AuthController.authenticate);
app.post('/api/register', RegistrationController.register);
app.listen(8012);
Pros-cons:
1-st example will simply read index.html once to variable and will serve that content, but will need restarting the app to re-read that file.
2-nd example is using .html
files inside views
folder as ejs
files, that gives opportunity to pass variables to html files which is better that simply sending files, + You can include one html inside of another using <% include partials/header.ejs %>
edited Mar 21 at 21:54
answered Mar 21 at 21:49
num8ernum8er
12k22240
12k22240
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like.sendFile
andstatic
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS/
route and compare sendFile vs cached content serving
– num8er
Mar 21 at 22:07
1
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
add a comment |
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like.sendFile
andstatic
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS/
route and compare sendFile vs cached content serving
– num8er
Mar 21 at 22:07
1
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
Second option is great, but the first has several flaws, starting by the fact that it's using sync programming in NodeJS, and that express has a built-in function to serve files
– Nino Filiu
Mar 21 at 21:56
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like
.sendFile
and static
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS /
route and compare sendFile vs cached content serving– num8er
Mar 21 at 22:07
@NinoFiliu I'm not saying that Express does not have builtin function for sending files. I'm saying that You can cache the file contents into file and never do i/o with disk drive every time when request hits root route. Also You know that express has static file server middleware, and index.html is static file for that case. In fact as person who serves static files using NGinx I don't like
.sendFile
and static
middlewares. So that's why I've done it wisely and cached the file. It makes difference when You DDOS /
route and compare sendFile vs cached content serving– num8er
Mar 21 at 22:07
1
1
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
Oh, okay then! I didn't look at it that way, thanks for the tips :)
– Nino Filiu
Mar 21 at 22:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288329%2fcannot-get-in-node-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The path
/
is handled and returns an empty object. If you're really trying to get the error message, try remove the part of code where it says
app.get(...
– Kevin Pastor
Mar 21 at 20:32