Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Set Node Type using js-use


Level 1

Hi everyone, im new to aem and using aem 6.5 now, and i want to ask a question, is it possible to set node type when creating new node at the same time, ive followed several tutorial, most of the are using java, but usually it also work when i convert it to js, heres the example:

this code below work on java :

 fileNode = root.addNode("image-1", "nt:file");

but thats not work in JS, it work in js if im only creating node without set the node type, like this code below :  

var fileNode = root.addNode("image-1");

ive also try to set the node type using node.setPrimaryType but it still didnt work.
any suggestion to make it work in JS ? or any article that ican read. thank you.

1 Reply


Community Advisor

use(function () {

var session = request.resourceResolver.adaptTo(javax.jcr.Session);
var node = request.resourceResolver.getResource("/content/dam/demo").adaptTo(javax.jcr.Node);
var node1 = node.addNode("debal-aem-resource" ,"nt:file");
var node2 = node1.addNode("jcr:content","dam:AssetContent");;
var path = node1.getPath();

return {

nodepath :path



Printing newly created node path to test -


<sly data-sly-use.custom="createnode.js">


GeDam node path below -



Hope this will help. Why are you planning to create node with specific node type using js use api ?