Reputation: 6408
I have created a brand new express API application and for some reason when I run it (the command is node src/index.js
) both requests hang and there is never a response. I have been able to nail it down to the app.use(express.json)
line as the culprit. When it is commented out the requests seem to work, but then I do not get access to request body.
const app = express();
app.use(express.json);
app.post("/api/user/register", (req, res) => {
res.send("Ok");
});
app.listen(3000, () => {
console.log("API is up and running!");
});
The contents of my package.json file is as follows:
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
I am currently running node version 13.2.0. Any suggestions on what to try next? (I'm new to node so any help would be appreciated)
Upvotes: 4
Views: 3148
Reputation: 6408
It's supposed to be app.use(express.json());
not app.use(express.json);
Upvotes: 10