unresolved function or method
I have "unresolved function or method" when I tried to add a user (app.post) as defined here.
I have "Node.JS Core library" under "Node.js and NPM" enabled, and also "NodeJS/node_modules" under "Libraries".
"app.get" works, but "app.post" or "app.delete" doesn't.
Please sign in to leave a comment.
the problem is that these properties are not defined in Express module - they are added dynamically in runtime. That's why WebStorm can't resolve them using static analysis.
As a workaround you can try installing 'express', 'serve-static' and 'express-serve-static-core' Typescript stubs via Settings | Languages & Frameworks | JavaScript | Libraries, Download...
Now it compiles, but I keep getting "Cannot GET /addUser" or about delete.
this error is shown as you didn't instruct your server how to respond on GET /addUser. You need adding
I copy/pasted my code, and as I have said - get works but post doesn't. So if at the begging post didn't *compile*, now it doesn't *work* (also deleteUser doesn't work).
The full (un-working) code:
var express = require('express');
var app = express();
var fs = require("fs");
var user = {
"user4" : {
"name" : "mohit",
"password" : "password4",
"profession" : "teacher",
"id": 4
}
}
app.post('/addUser', function (req, res) {
// First read existing users.
fs.readFile( __dirname + "/" + "users.json", 'utf8', function (err, data) {
data = JSON.parse( data );
data["user4"] = user["user4"];
console.log( data );
res.end( JSON.stringify(data));
});
})
var server = app.listen(8082, function (err ) {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
Please see my previous reply:) If you need an advise of developing your Express app, I'd suggest asking on StackOverflow - this forum is mostly intended for discussing IDE problems
I'm sorry I keep nagging, but the thing is - I saw your previous replay, that said
The thing is - in my code I should enter
app.post('/addUser', function (req, res) {("post" and not "get"). So still "get" works but "post" doesn't. Is the guide wrong?
let me explain... When you open http://localhost:8082/addUser in browser, you perform a GET request your server should handle... But you don't have any code that handles this request - the only method you have handles POST. You can try some REST client to post a request to your server - it will respond with expected JSON. But GET request will fail
Ohhh I thought that Chrome can be the client... Thank you!